Define_call or Define_function?
Spire_Jeff
Posts: 1,917
This time I am testing the difference between define_call and define_function. I am using the switch case methods from the previous tests, only instead of having the for loop being inside the call/function, this time I am calling the function/call from a for lop and passing the value of the for loop counter in addition to the data array.
No big elaboration required on this one as it is simply a comparison between functions and calls. I am running the test 3 times on each method. Using all 'A's, all 'Z's, and a random array of characters.
I really don't expect to see a big difference between the two methods, but we shall see.
Here are the results:
Well, it seems that define_call is consistently slightly slower, but 19ms over 10000 calls is negligible as far as I can see. The only thought I have is that if multiple different define_calls and define_functions are used, maybe the overhead is higher? I will try to perform further tests on this to explore this thought, but as of right now, it seems to be personal preference that should dictate the method you use.
A quick test with 1000 iterations seems to indicate define calls to be about 2ms/1000 calls slower than functions. I would call this negligible, but you be the judge. (I also ran the test with 100,000 iterations and the ~2ms/1000 calls value still held true)
Jeff
No big elaboration required on this one as it is simply a comparison between functions and calls. I am running the test 3 times on each method. Using all 'A's, all 'Z's, and a random array of characters.
I really don't expect to see a big difference between the two methods, but we shall see.
Here are the results:
Line 1 (18:53:33):: ********************************************************* Line 2 (18:53:33):: * TEST 1 REPORT: SwitchCase "A" Function Line 3 (18:53:33):: * Most recent 5 runs: Line 4 (18:53:33):: * 1: 2402ms Line 5 (18:53:33):: * 2: 2402ms Line 6 (18:53:33):: * 3: 2402ms Line 7 (18:53:33):: * 4: 2402ms Line 8 (18:53:33):: * 5: 2401ms Line 9 (18:53:33):: *---------------------------------------------------------- Line 10 (18:53:33):: * Average run time: 2401ms - over 5 tests Line 11 (18:53:33):: ********************************************************* Line 12 (18:53:33):: ********************************************************* Line 13 (18:53:33):: * TEST 2 REPORT: SwitchCase "Z" Function Line 14 (18:53:33):: * Most recent 5 runs: Line 15 (18:53:33):: * 1: 2566ms Line 16 (18:53:33):: * 2: 2568ms Line 17 (18:53:33):: * 3: 2565ms Line 18 (18:53:33):: * 4: 2568ms Line 19 (18:53:33):: * 5: 2568ms Line 20 (18:53:33):: *---------------------------------------------------------- Line 21 (18:53:33):: * Average run time: 2566ms - over 5 tests Line 22 (18:53:33):: ********************************************************* Line 23 (18:53:33):: ********************************************************* Line 24 (18:53:33):: * TEST 3 REPORT: SwitchCase "Random" Function Line 25 (18:53:33):: * Most recent 5 runs: Line 26 (18:53:33):: * 1: 2477ms Line 27 (18:53:33):: * 2: 2483ms Line 28 (18:53:33):: * 3: 2478ms Line 29 (18:53:33):: * 4: 2477ms Line 30 (18:53:33):: * 5: 2475ms Line 31 (18:53:33):: *---------------------------------------------------------- Line 32 (18:53:33):: * Average run time: 2477ms - over 5 tests Line 33 (18:53:33):: ********************************************************* Line 34 (18:53:33):: ********************************************************* Line 35 (18:53:33):: * TEST 4 REPORT: SwitchCase "A" Call Line 36 (18:53:33):: * Most recent 5 runs: Line 37 (18:53:33):: * 1: 2419ms Line 38 (18:53:33):: * 2: 2418ms Line 39 (18:53:33):: * 3: 2417ms Line 40 (18:53:33):: * 4: 2418ms Line 41 (18:53:33):: * 5: 2418ms Line 42 (18:53:33):: *---------------------------------------------------------- Line 43 (18:53:33):: * Average run time: 2417ms - over 5 tests Line 44 (18:53:33):: ********************************************************* Line 45 (18:53:33):: ********************************************************* Line 46 (18:53:33):: * TEST 5 REPORT: SwitchCase "Z" Call Line 47 (18:53:33):: * Most recent 5 runs: Line 48 (18:53:33):: * 1: 2589ms Line 49 (18:53:33):: * 2: 2591ms Line 50 (18:53:33):: * 3: 2589ms Line 51 (18:53:33):: * 4: 2589ms Line 52 (18:53:33):: * 5: 2590ms Line 53 (18:53:33):: *---------------------------------------------------------- Line 54 (18:53:33):: * Average run time: 2589ms - over 5 tests Line 55 (18:53:33):: ********************************************************* Line 56 (18:53:33):: ********************************************************* Line 57 (18:53:33):: * TEST 6 REPORT: SwitchCase "Random" Call Line 58 (18:53:33):: * Most recent 5 runs: Line 59 (18:53:33):: * 1: 2509ms Line 60 (18:53:33):: * 2: 2508ms Line 61 (18:53:33):: * 3: 2509ms Line 62 (18:53:33):: * 4: 2507ms Line 63 (18:53:33):: * 5: 2511ms Line 64 (18:53:33):: *---------------------------------------------------------- Line 65 (18:53:33):: * Average run time: 2507ms - over 5 tests Line 66 (18:53:33):: *********************************************************
Well, it seems that define_call is consistently slightly slower, but 19ms over 10000 calls is negligible as far as I can see. The only thought I have is that if multiple different define_calls and define_functions are used, maybe the overhead is higher? I will try to perform further tests on this to explore this thought, but as of right now, it seems to be personal preference that should dictate the method you use.
A quick test with 1000 iterations seems to indicate define calls to be about 2ms/1000 calls slower than functions. I would call this negligible, but you be the judge. (I also ran the test with 100,000 iterations and the ~2ms/1000 calls value still held true)
Jeff
0