Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Functions - Not Always

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Functions - Not Always

    I've never taken much advantage of UDF's. I recently started putting much more often used logic into functions. Curious as to the difference in using these functions in large batch scripts or Alpha operations with many records as opposed to keeping the expression at the execution point, I ran a little test. I used a function posted by Ira for finding the last day of a month. Here it is.

    ''XBasic
    dim datevalue as d
    datevalue = {01/01/01}

    'rem function test
    t1 = toseconds(time())
    For x = 1 to 50000
    lastday = monthend(datevalue)
    Next x
    t2 = toseconds(time())
    trace.writeln("Function Test for " + dtoc(lastday) + " - Seconds elapsed:"+STR(t2-t1))

    'rem non function test
    t1 = toseconds(time())
    For x = 1 to 50000
    lastday = if(DateValue={},{},Addmonths(DateValue-Day(DateValue)+1,1)-1)
    Next x
    t2 = toseconds(time())
    trace.writeln("Non Function Test for " + dtoc(lastday) + " - Seconds elapsed:"+STR(t2-t1))
    end

    'rem code for monthend function
    'function MonthEnd as D(DateVal as D)
    ' MonthEnd=iif(DateVal={},{},Addmonths(DateVal-Day(DateVal)+1,1)-1)
    'end function


    From the trace window:
    Function Test for 01/01/2001 - Seconds elapsed: 41
    Non Function Test for 01/01/2001 - Seconds elapsed: 10

    The only difference I can see is that caused by calling the function. I realize that the time difference between the two processes divided by 50000 is small (6 ten thousandths of a second), but my conclusion is that I will still use functions much more frequently, just not in large batch processes or queries where the function has to be called in every iteration.

    John

    #2
    RE: Functions - Not Always

    John,

    Here here! I've just finished doing the same thing and have found basically the same results as you would expect.

    I'm just wrapping up a function now that changes a series of user-selected field names, with any combination of disparate field types (C, N, D, L), into a single character expression for adhoc report sortation.

    Creating a function to convert up to 5 field names/types into a compound sort string now allows me to send grouping and sortation specs to my report template on the fly, but the real benefit I've discovered is the ability to reuse UDF's over and over again in other scripts. Who knew?

    Best regards,

    Geoff Hollander

    Comment


      #3
      RE: Functions - Not Always

      Hi John,

      You did not try it with an embedded function, which is a little faster than an external function. The code would look like this


      ''XBasic
      dim datevalue as d
      datevalue = {01/01/01}

      'rem function test
      t1 = toseconds(time())
      For x=1 to 50000
      lastday=monthend(datevalue)
      Next x
      t2 = toseconds(time())
      trace.writeln("Function Test for "+dtoc(lastday)+" - Seconds elapsed:"+STR(t2-t1))

      'rem function test
      t1 = toseconds(time())
      For x = 1 to 50000
      lastday = monthendi(datevalue)
      Next x
      t2 = toseconds(time())
      trace.writeln("Imbedded Function Test for " + dtoc(lastday) + " - Seconds elapsed:"+STR(t2-t1))

      'rem non function test
      t1 = toseconds(time())
      For x = 1 to 50000
      lastday = if(DateValue={},{},Addmonths(DateValue-Day(DateValue)+1,1)-1)
      Next x
      t2 = toseconds(time())
      trace.writeln("Non Function Test for " + dtoc(lastday) + " - Seconds elapsed:"+STR(t2-t1))

      'rem loop only test
      t1 = toseconds(time())
      For x = 1 to 50000
      ' lastday = if(DateValue={},{},Addmonths(DateValue-Day(DateValue)+1,1)-1)
      Next x
      t2 = toseconds(time())
      trace.writeln("Loop Only Test for " + dtoc(lastday) + " - Seconds elapsed:"+STR(t2-t1))
      end



      '***************************
      'rem code for monthendi function
      function MonthEndi as D(DateVal as D)
      MonthEndi=iif(DateVal={},{},Addmonths(DateVal-Day(DateVal)+1,1)-1)
      end function

      '***************************
      'rem code for monthend function place in an external function
      'function MonthEnd as D(DateVal as D)
      'MonthEnd=iif(DateVal={},{},Addmonths(DateVal-Day(DateVal)+1,1)-1)
      'end function


      My times were:

      Function Test for 01/31/2001 - Seconds elapsed: 12
      Imbedded Function Test for 01/31/2001 - Seconds elapsed: 11
      Non Function Test for 01/31/2001 - Seconds elapsed: 3
      Loop Only Test for 01/31/2001 - Seconds elapsed: 1


      However, your test shows what the overhead for a simple function is. The more code it is, the less the overhead matters. It may possibly faster in version 5 with precompiled add-ins.

      It would be nice if Alpha could have a macro substition (includes) so that code could be expanded inline. It may also be possible for Alpha to possibly improve function overhead by caching and other tricks, although these may already be done.

      Nevertheless, the real issue, that you illustrate is that for a simplistic function that is in the middle of a loop that is called many times, you are better to embed the code than have a function call. Outside a loop, the overhead is so trivial, that the simplification of the code by using function calls is the preferred method.


      Regards,

      Ira J. Perlow
      Computer Systems Design & Associates
      [email protected]
      Regards,

      Ira J. Perlow
      Computer Systems Design


      CSDA A5 Products
      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
      CSDA Barcode Functions

      CSDA Code Utility
      CSDA Screen Capture


      Comment


        #4
        RE: Functions - Not Always

        John,

        One other thing though.

        Suppose you changed the code to something like this,


        'rem function test
        t1 = toseconds(time())
        lastday=monthend(datevalue,50000)
        t2 = toseconds(time())
        trace.writeln("Function Test for "+dtoc(lastday)+" - Seconds elapsed:"+STR(t2-t1))
        end

        '***************************
        'rem code for monthend function place in an external function
        'function MonthEnd as D(DateVal as D,RepeatCount as N)
        'For x=1 to RepeatCount
        'MonthEnd=iif(DateVal={},{},Addmonths(DateVal-Day(DateVal)+1,1)-1)
        'Next
        'end function


        What you have done, and in general should do, is move code that has to be tightly written together into the function. Now the overhead of the function call will have little importance.

        This is essentially what Alpha has done with their product. Make the major database operations a primitive (and thus very efficient, like indexing, updates, exports etc) and make the front end (user interface) more interpretive where speed is not particularly important.

        Regards,

        Ira J. Perlow
        Computer Systems Design & Associates
        [email protected]
        Regards,

        Ira J. Perlow
        Computer Systems Design


        CSDA A5 Products
        New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
        CSDA Barcode Functions

        CSDA Code Utility
        CSDA Screen Capture


        Comment

        Working...
        X