https://twitter.com/_ianks/status/1108950820354031618
Version
$ ruby -v
ruby 2.6.0preview2 (2018-05-31 trunk 63539) +JIT [x86_64-darwin17]
With JIT
$ time ruby --jit -e w,h=$COLUMNS/2-1,$LINES'
walkers = []
10.times do
walkers << [
"\e[4#{rand(7)+1}m",
[[rand(w),rand(h)]]*10
]
end
show = lambda { |(x,y)| "\e[#{y+1};#{2*x+1}H " }
1000.times do
print "\e[0m" + walkers.map { |_color, points| show[points.pop] }.join
walkers.each do |color, points|
x, y = points[0]
x = (x+rand(3)-1) % w
y = (y+rand(3)-1) % h
points.unshift [x, y]
print color + points.map(&show).join
end
sleep 0.01
end
puts "\e[0m"
'
12.72 real 11.64 user 1.98 sys
Without JIT
$ time ruby -e w,h=$COLUMNS/2-1,$LINES'
walkers = []
10.times do
walkers << [
"\e[4#{rand(7)+1}m",
[[rand(w),rand(h)]]*10
]
end
show = lambda { |(x,y)| "\e[#{y+1};#{2*x+1}H " }
1000.times do
print "\e[0m" + walkers.map { |_color, points| show[points.pop] }.join
walkers.each do |color, points|
x, y = points[0]
x = (x+rand(3)-1) % w
y = (y+rand(3)-1) % h
points.unshift [x, y]
print color + points.map(&show).join
end
sleep 0.01
end
puts "\e[0m"
'
12.27 real 0.56 user 0.14 sys