Skip to content

Commit a6c0655

Browse files
committed
Add benchmark for the "cute" flipflop-based fractal generator.
1 parent 0221137 commit a6c0655

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

bench/bench_flipflop_fractal.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'benchmark'
2+
3+
def fractal_flipflop
4+
w, h = 44, 54
5+
c = 7 + 42 * w
6+
a = [0] * w * h
7+
g = d = 0
8+
f = proc do |n|
9+
a[c] += 1
10+
o = a.map {|z| " :#"[z, 1] * 2 }.join.scan(/.{#{w * 2}}/)
11+
puts "\f" + o.map {|l| l.rstrip }.join("\n")
12+
d += 1 - 2 * ((g ^= 1 << n) >> n)
13+
c += [1, w, -1, -w][d %= 4]
14+
end
15+
1024.times do
16+
!!(!!(!!(!!(!!(!!(!!(!!(!!(true...
17+
f[0])...f[1])...f[2])...
18+
f[3])...f[4])...f[5])...
19+
f[6])...f[7])...f[8])
20+
end
21+
end
22+
23+
(ARGV[0] || 5).to_i.times do
24+
puts Benchmark.measure { fractal_flipflop }
25+
end

0 commit comments

Comments
 (0)