LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Performance of state machine with enum vs string?


@rbrown_acertaralabs wrote:

I'm pasting screenshots of the VI block diagrams rather than the source code, since images can be viewed immediately in the browser.   


Is there a reason you didn't post it as a snippet which is also viewable in the browser and executable code?  Or post the pictures and a zip of the source?

0 Kudos
Message 31 of 46
(1,118 Views)

Good idea to run it with case-insensitive match. To my surprise, this made a HUGE difference and drastically increased the time required for the string case:

  • Typedef Enum = 0.853 sec per 10M iterations
  • String (case insensitive match) = 84.3 sec per 10M iterations (!)

For the string case, one of the items is set as the Default case. I have posted the above results in the latest post to this topic (along with source code).

0 Kudos
Message 32 of 46
(1,100 Views)

I intentionally did not randomly select the strings (nor the ints from the enum) during loop execution since random selection processing would add to the processing time for both the enum case and the string case. I wanted the timing to be strictly based on the case selection logic. Thus, the string array is pre-populated and the enum int array is pre-populated. However, both are pre-populated (before the timing begins) in a random order.

 

You are correct that the pre-populated enum int array could have duplicates -- I have fixed this and re-posted the new results in my latest post to this topic. It did not significantly change the results:

  • Typedef Enum = 0.843 sec per 10M iterations
  • String = 11.2 sec per 10M iterations
  • String (case insensitive match) = 84.3 sec per 10M iterations (!)
0 Kudos
Message 33 of 46
(1,097 Views)

Thanks for pointing out the snippet option.  I have now simply posted the entire source code in my latest post on this topic.

0 Kudos
Message 34 of 46
(1,095 Views)

Latest results, screenshots, and source code attached.

 

Results:

  • Typedef Enum = 0.843 sec per 10M iterations
  • String = 11.2 sec per 10M iterations
  • String (case insensitive match) = 84.3 sec per 10M iterations (!)

000736.jpg000737.jpg000735.jpg000734.jpg

Download All
Message 35 of 46
(1,093 Views)

Still no source code, but nice testing.

 

mcduff

0 Kudos
Message 36 of 46
(1,092 Views)

see previous post for source code

0 Kudos
Message 37 of 46
(1,089 Views)

Try it with Disable Debugging, you may be surprisedSmiley Wink.

 

mcduff

0 Kudos
Message 38 of 46
(1,086 Views)

@mcduff wrote:

Try it with Disable Debugging, you may be surprisedSmiley Wink.


The reason for the "surprise" is Constant Folding.  Nothing is coming out of these case structures, so they will likely be removed from the compiled code when debugging has been disabled.  If there was a value that came out of the case structure and wrote to a control, then we would have a more valid benchmark.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 39 of 46
(1,060 Views)

@crossrulz Thanks for the explanation.

0 Kudos
Message 40 of 46
(1,058 Views)