Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def do_math(a : Vector(Type, Size), b : Vector(Type, Size))
- @elements.each_index do |i|
- @elements[i] = yield a[i], b[i]
- end
- end
- def do_unrolled_math(a : Vector(Type, Size), b : Vector(Type, Size))
- @elements[0] = yield a[0], b[0]
- @elements[1] = yield a[1], b[1]
- end
- Benchmark.ips do |x|
- x.report("loop") { res.do_math(foo, bar) { |a, b| a + b } }
- x.report("unrolled") { res.do_unrolled_math(foo, bar) { |a, b| a + b } }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement