Ugo DI LUCA Posted May 19, 2003 Posted May 19, 2003 Hi, I was wondering what could be the difference from these 2 Case Statement structures. Is one more efficient that the other ? Why ? Case(Value = "A", "Result 1", Value = "B", "Result 2", Value = "C", "Result 3") Case(Value = "A", "Result 1", Case(Value = "B", "Result 2", "Result 3")) Just curious about it
danjacoby Posted May 19, 2003 Posted May 19, 2003 The difference is if the Value="D". In the first example, you get nothing; in the second, you get "Result 3". Flippant of me, I know.
Ugo DI LUCA Posted May 19, 2003 Author Posted May 19, 2003 Thanks Dan, I knew I was missing something obvious. I thought the empty result would have come with : Case(Value = "A", "Result 1", Value = "B", "Result 2", Value = "C", "Result 3", " "), that is the last " ".... Thanx again.
cjaeger Posted May 19, 2003 Posted May 19, 2003 as for timing - the nested case seems to be a little bit slower ... don't know why. just see attached test file (& correct the calc, that did escape me, dan ..) caseTest.zip
cjaeger Posted May 19, 2003 Posted May 19, 2003 had to delete sample records because of upload limit - have a look at the script to create new ones ...
Ugo DI LUCA Posted May 19, 2003 Author Posted May 19, 2003 Hi Christian, Thank you to reply in depth to my question. Yes, apart from my errors about the empties, I had tested both methods while creating the calcs for the "Minimum Quantity in Stock" (you surely remember this thread), and I also had the feeling that a nested could be slower from a classic case. Now, I don't have any idea of what I should see on your sample. My apologizes ;
cjaeger Posted May 19, 2003 Posted May 19, 2003 >Now, I don't have any idea of what I should see on your sample. My apologizes Instructions: Open case-test.fp5 run script "make records" - this will create 20,000 records the run script "run tests-start" or just have a look at the results - a negative av(erage) means that case statement # 1 is faster than nested case statement #2. The file replaces the field "test" using both case statements, recording script start time & end time before each run. In case results the time needed to run the replacement are recorded...
paulage77 Posted May 19, 2003 Posted May 19, 2003 It seems the nested case would be slower as the resulting abstract syntax tree would be wider/deeper to traverse.
Ugo DI LUCA Posted May 19, 2003 Author Posted May 19, 2003 Well, in my mind, the nested would have eliminated first cases and concentrates the calcs only on the residual "true" results. This seems to me a quicker process. Not sure I make me clear, but I still think it's strange. BTW Christian....great test !
paulage77 Posted May 20, 2003 Posted May 20, 2003 That is a good point. What I mean, is that the resulting data structure for any nested conditional is larger than for single conditionals. More branches to look at and evaluate.
Recommended Posts
This topic is 7929 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now