![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Ok fellow propeller-heads, I've got a case (no pun intended) of elegance over efficiency. Which is more efficient? Sample1: FOR II = 1 TO 100 MASSAGE SOME DATA per II SET COUNTER per II BEGIN CASE CASE SOMETHING1 DO STUFF1 WITH II,DATA,COUNTER CASE SOMETHING2 DO STUFF2 WITH II,DATA,COUNTER CASE SOMETHING3 DO STUFF3 WITH II,DATA,COUNTER CASE SOMETHING4 DO STUFF4 WITH II,DATA,COUNTER CASE SOMETHING5 DO STUFF5 WITH II,DATA,COUNTER END CASE NEXT II Sample2: BEGIN CASE CASE SOMETHING1 FOR II = 1 TO 100 MASSAGE SOME DATA per II SET COUNTER per II DO STUFF1 WITH II,DATA,COUNTER NEXT II CASE SOMETHING2 FOR II = 1 TO 100 SET COUNTER per II MASSAGE SOME DATA per II SET COUNTER per II DO STUFF2 WITH II,DATA,COUNTER NEXT II CASE SOMETHING3 FOR II = 1 TO 100 MASSAGE SOME DATA per II SET COUNTER per II DO STUFF3 WITH II,DATA,COUNTER NEXT II CASE SOMETHING4 FOR II = 1 TO 100 MASSAGE SOME DATA per II SET COUNTER per II DO STUFF4 WITH II,DATA,COUNTER NEXT II CASE SOMETHING5 FOR II = 1 TO 100 MASSAGE SOME DATA per II SET COUNTER per II DO STUFF5 WITH II,DATA,COUNTER NEXT II END CASE I'm thinking Sample2 is more efficient because there are only five case scans vs an average of 2.5 x 100 case scans in Sample1. But I hate to employ the same code over and over. Sample1 looks nicer, but the thought of all those CASE tests is giving me the willies. Which one and why? Thanks! Ed |
#3
| |||
| |||
|
|
A third possibility is to make a function of the repeated code. *But I would probably go with sample one because it looks easier to maintain and there isn't much to be gained by optimizing the code with modern machines. Different strokes for different folks. BobJ "Ed Sheehan" <NOedsS... (AT) xmission (DOT) com> wrote in message news:hsrgck$j4e$1 (AT) news (DOT) xmission.com... Ok fellow propeller-heads, I've got a case (no pun intended) of elegance over efficiency. Which is more efficient? Sample1: FOR II = 1 TO 100 * MASSAGE SOME DATA per II * SET COUNTER per II * BEGIN CASE * * *CASE SOMETHING1 * * * * DO STUFF1 WITH II,DATA,COUNTER * * *CASE SOMETHING2 * * * * DO STUFF2 WITH II,DATA,COUNTER * * *CASE SOMETHING3 * * * * DO STUFF3 WITH II,DATA,COUNTER * * *CASE SOMETHING4 * * * * DO STUFF4 WITH II,DATA,COUNTER * * *CASE SOMETHING5 * * * * DO STUFF5 WITH II,DATA,COUNTER * END CASE NEXT II Sample2: BEGIN CASE * CASE SOMETHING1 * * *FOR II = 1 TO 100 * * *MASSAGE SOME DATA per II * * *SET COUNTER per II * * * * DO STUFF1 WITH II,DATA,COUNTER * * *NEXT II * CASE SOMETHING2 * * *FOR II = 1 TO 100 * * * * SET COUNTER per II * * * * MASSAGE SOME DATA per II * * * * SET COUNTER per II * * * * DO STUFF2 WITH II,DATA,COUNTER * * *NEXT II * CASE SOMETHING3 * * *FOR II = 1 TO 100 * * * * MASSAGE SOME DATA per II * * * * SET COUNTER per II * * * * DO STUFF3 WITH II,DATA,COUNTER * * *NEXT II * CASE SOMETHING4 * * *FOR II = 1 TO 100 * * * * MASSAGE SOME DATA per II * * * * SET COUNTER per II * * * * DO STUFF4 WITH II,DATA,COUNTER * * *NEXT II * CASE SOMETHING5 * * *FOR II = 1 TO 100 * * * * MASSAGE SOME DATA per II * * * * SET COUNTER per II * * * * DO STUFF5 WITH II,DATA,COUNTER * * *NEXT II END CASE I'm thinking Sample2 is more efficient because there are only five case scans vs an average of 2.5 x 100 case scans in Sample1. But I hate to employ the same code over and over. Sample1 looks nicer, but the thought of all those CASE tests is giving me the willies. Which one and why? Thanks! Ed |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
... and there isn't much to be gained by optimizing the code with modern machines. |
#6
| |||
| |||
|
|
Why don't you plug in some data & tell us?!?!? Tooooooo many unknowns, like platform, what DOSTUFF actually does, placement of code in memory (eg: may cross a frame boundary & cause frame faults) You have already given an answer that seems logical(ish) ..... but I'd suggest for a lopp of 100 items on a system installed this century .... does it really matter??!?! Slow news day?!? |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
Awesome! Thanks M. I was thinking about delving that deep into it, but concluded the time would be too costly right now. I am still wondering about the cost per instruction compared to, say, a string extraction or read/write. I'm hoping the cost is small, because I'm still using Sample2 for now. Thanks again, Ed Not a problem, had a few minutes and I love tearing into code to |
#9
| |||
| |||
|
|
Ok fellow propeller-heads, I've got a case (no pun intended) of elegance over efficiency. Which is more efficient? Sample1: FOR II = 1 TO 100 * *MASSAGE SOME DATA per II * *SET COUNTER per II * *BEGIN CASE * * * CASE SOMETHING1 * * * * *DO STUFF1 WITH II,DATA,COUNTER * * * CASE SOMETHING2 * * * * *DO STUFF2 WITH II,DATA,COUNTER * * * CASE SOMETHING3 * * * * *DO STUFF3 WITH II,DATA,COUNTER * * * CASE SOMETHING4 * * * * *DO STUFF4 WITH II,DATA,COUNTER * * * CASE SOMETHING5 * * * * *DO STUFF5 WITH II,DATA,COUNTER * *END CASE NEXT II Sample2: BEGIN CASE * *CASE SOMETHING1 * * * FOR II = 1 TO 100 * * * MASSAGE SOME DATA per II * * * SET COUNTER per II * * * * *DO STUFF1 WITH II,DATA,COUNTER * * * NEXT II * *CASE SOMETHING2 * * * FOR II = 1 TO 100 * * * * *SET COUNTER per II * * * * *MASSAGE SOME DATA per II * * * * *SET COUNTER per II * * * * *DO STUFF2 WITH II,DATA,COUNTER * * * NEXT II * *CASE SOMETHING3 * * * FOR II = 1 TO 100 * * * * *MASSAGE SOME DATA per II * * * * *SET COUNTER per II * * * * *DO STUFF3 WITH II,DATA,COUNTER * * * NEXT II * *CASE SOMETHING4 * * * FOR II = 1 TO 100 * * * * *MASSAGE SOME DATA per II * * * * *SET COUNTER per II * * * * *DO STUFF4 WITH II,DATA,COUNTER * * * NEXT II * *CASE SOMETHING5 * * * FOR II = 1 TO 100 * * * * *MASSAGE SOME DATA per II * * * * *SET COUNTER per II * * * * *DO STUFF5 WITH II,DATA,COUNTER * * * NEXT II END CASE I'm thinking Sample2 is more efficient because there are only five case scans vs an average of 2.5 x 100 case scans in Sample1. But I hate to employ the same code over and over. Sample1 looks nicer, but the thought of all those CASE tests is giving me the willies. Which one and why? Thanks! Ed |
I don't know --![]() |
| Thread Tools | |
| Display Modes | |
| |