feat: add range operators and iterator protocol for numeric for loops
Implement `..` and `...` infix operators on Num returning Range objects that support the iterator protocol, enabling concise numeric for loops like `for (i in 1..10)`. Add Range class with min/max properties and iterate/iteratorValue methods. Introduce TOKEN_DOTDOT and TOKEN_DOTDOTDOT lexer tokens with PREC_RANGE precedence in the compiler. Unroll method_call benchmark loops across all languages to stress dynamic dispatch instead of loop overhead, reducing iteration count from 1M to 100K with 10x unrolling. Update Wren benchmarks (binary_trees, fib, for) to use new range syntax. Add benchmark/README.md documenting each benchmark's purpose.
This commit is contained in:
@@ -29,14 +29,21 @@ class NthToggle is Toggle {
|
||||
}
|
||||
|
||||
var start = OS.clock
|
||||
var n = 1000000
|
||||
var i = 0
|
||||
var n = 100000
|
||||
var val = true
|
||||
var toggle = new Toggle(val)
|
||||
|
||||
while (i < n) {
|
||||
for (i in 0...n) {
|
||||
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
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
IO.write(toggle.value)
|
||||
@@ -44,10 +51,17 @@ IO.write(toggle.value)
|
||||
val = true
|
||||
var ntoggle = new NthToggle(val, 3)
|
||||
|
||||
i = 0
|
||||
while (i < n) {
|
||||
for (i in 0...n) {
|
||||
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
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
IO.write(ntoggle.value)
|
||||
|
||||
Reference in New Issue
Block a user