Wiki

Ticket #133 (closed enhancement: fixed)

Opened 16 years ago

Last modified 16 years ago

Optimization: Make "for i in c" as fast as "for i = 0 .. c"

Reported by: Chuck Owned by: Chuck
Priority: minor Milestone:
Component: Cobra Compiler Version: 0.8.0
Keywords: optimization Cc:

Description

If possible, make the new, approved

for i in c

loop as fast as the old, deprecated

for i = 0 .. c

loop -- without breaking any semantics, of course!

The new loop is about 2 X slower than the old according to this program:

use System.Diagnostics


class P

	def main is shared
		count = 2_000_000_000

		sw = Stopwatch()
		trace Stopwatch.isHighResolution

		sw.start		
		for i = 0 .. count
			pass
		sw.stop
		t1 = sw.elapsedMilliseconds
		print t1

		sw.reset		
		sw.start		
		for j in count
			pass
		sw.stop
		t2 = sw.elapsedMilliseconds
		print t2
		
		print t2 / t1, ' X slower'

Attachments

numericFor-opt.patch Download (2.0 KB) - added by hopscc 16 years ago.

Change History

Changed 16 years ago by hopscc

Changed 16 years ago by hopscc

  • owner set to Chuck
  • status changed from new to assigned

Heres an optimisation for the common case (none given or positive integer step).
On my system it runs faster than old form

> cobc0  forinSpeed.cobra
trace: Stopwatch.isHighResolution=true; at forinSpeed.cobra:10; in P.main
1492
1207
0.808981233243967828418230563  X slower
> ./forinSpeed.exe
trace: Stopwatch.isHighResolution=true; at forinSpeed.cobra:10; in P.main
1364
1220
0.8944281524926686217008797654  X slower
> ./forinSpeed.exe
trace: Stopwatch.isHighResolution=true; at forinSpeed.cobra:10; in P.main
1560
1223
0.783974358974358974358974359  X slower

Changed 16 years ago by Chuck

  • status changed from assigned to closed
  • resolution set to fixed

Thanks. Fixed in changeset:1904

On my machine the factor is now .97 - 1.01.

Note: See TracTickets for help on using tickets.