Range operators!

Added ".." and "..." infix operators. Num implements them to
return Range objects. Those in turn implement the iterator
protocol, so now numeric for loops are easy:

    for (i in 1..10) { ... }

I also cleaned up the Wren benchmarks to use this.

In the process, I discovered the method_call benchmark really
just showed loop peformance, so I unrolled the loops in all of
the languages to stress method calls.
This commit is contained in:
Bob Nystrom
2013-12-25 15:01:45 -08:00
parent 2b65e47747
commit 507e89d3b3
12 changed files with 209 additions and 44 deletions
+19 -1
View File
@@ -39,12 +39,21 @@ end
def main()
start = Time.now
n = 1000000
n = 100000
val = 1
toggle = Toggle.new(val)
n.times do
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
val = toggle.activate().value()
end
if val then puts "true" else puts "false" end
@@ -52,6 +61,15 @@ def main()
ntoggle = NthToggle.new(val, 3)
n.times do
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
val = ntoggle.activate().value()
end
if val then puts "true" else puts "false" end