Ticket #180 (new defect)
Optimization: Speed up use of literal collections
Reported by: | Chuck | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | Cobra Compiler | Version: | 0.8.0 |
Keywords: | optimization | Cc: |
Description
The program below demonstrates that Cobra's naive handling of something like:
if s in ['a', 'b'], ...
is rather slow. This creates a burden on the developer to write lower level code to get better performance.
use System.Diagnostics class P def main reps = 10_000_000 s = 'a' sw = Stopwatch() sw.start for i in reps if s in ['a', 'b', 'c', 'd', 'e', 'f'] s = 'a' sw.stop dur1 = sw.elapsedMilliseconds t = ['a', 'b', 'c', 'd', 'e', 'f'] sw.reset sw.start for i in reps if s in t # if s in List<of String>(t) s = 'a' sw.stop dur2 = sw.elapsedMilliseconds ratio = dur1 / dur2 trace dur1, dur2, ratio
Output:
trace: dur1=16482 (Int64); dur2=464 (Int64); ratio=35.521551724137931034482758621 (Decimal); at x-literal-list.cobra:27; in P.main
Change History
Note: See
TracTickets for help on using
tickets.