Advertisement
Guest User

Untitled

a guest
Jul 16th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. def do_math(a : Vector(Type, Size), b : Vector(Type, Size))
  2. @elements.each_index do |i|
  3. @elements[i] = yield a[i], b[i]
  4. end
  5. end
  6.  
  7. def do_unrolled_math(a : Vector(Type, Size), b : Vector(Type, Size))
  8. @elements[0] = yield a[0], b[0]
  9. @elements[1] = yield a[1], b[1]
  10. end
  11.  
  12. Benchmark.ips do |x|
  13. x.report("loop") { res.do_math(foo, bar) { |a, b| a + b } }
  14. x.report("unrolled") { res.do_unrolled_math(foo, bar) { |a, b| a + b } }
  15. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement