Advertisement
Guest User

Untitled

a guest
May 29th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. require 'benchmark'
  2.  
  3. n = 12352834
  4. t = 40000
  5.  
  6. Benchmark.bm do |x|
  7. x.report("Split map") do
  8. t.times { n.to_s.split('').map(&:to_i) }
  9. end
  10.  
  11. x.report("chars") do
  12. t.times { n.to_s.chars.map(&:to_i) }
  13. end
  14.  
  15. x.report("each byte") do
  16. t.times { n.to_s.each_byte.map { |x| x - 48 } }
  17. end
  18.  
  19. x.report("Numerical") do
  20. t.times { (0..Math.log10(n).to_i).map { |dp| n / 10 ** dp % 10 }.reverse }
  21. end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement