Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- n = 12352834
- t = 40000
- Benchmark.bm do |x|
- x.report("Split map") do
- t.times { n.to_s.split('').map(&:to_i) }
- end
- x.report("chars") do
- t.times { n.to_s.chars.map(&:to_i) }
- end
- x.report("each byte") do
- t.times { n.to_s.each_byte.map { |x| x - 48 } }
- end
- x.report("Numerical") do
- t.times { (0..Math.log10(n).to_i).map { |dp| n / 10 ** dp % 10 }.reverse }
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement