May 19, 200322 yr 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
May 19, 200322 yr 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.
May 19, 200322 yr Author 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.
May 19, 200322 yr 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
May 19, 200322 yr had to delete sample records because of upload limit - have a look at the script to create new ones ...
May 19, 200322 yr Author 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 ;
May 19, 200322 yr >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...
May 19, 200322 yr It seems the nested case would be slower as the resulting abstract syntax tree would be wider/deeper to traverse.
May 19, 200322 yr Author 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 !
May 20, 200322 yr 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.
Create an account or sign in to comment