Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def range_to_arr_1(range, step=15.seconds)
- range.step(step)
- end
- def range_to_arr_2(range, step=15.seconds)
- [].tap do |a|
- date = range.begin
- stop = range.end
- while date < stop do
- a << date
- date += step
- end
- end
- end
- r1 = Time.now...Time.now+15.minutes
- r2 = Time.zone.now...Time.zone.now+15.minutes
- n1 = 150
- n2 = 150
- Benchmark.bm do |x|
- x.report { for i in 1..n1; range_to_arr_1(r1); 1; end }
- x.report { for i in 1..n1; range_to_arr_2(r1); 1; end }
- x.report { for i in 1..n2; range_to_arr_1(r2); 1; end }
- x.report { for i in 1..n2; range_to_arr_2(r2); 1; end }
- end
- # user system total real
- # 0.280000 0.030000 0.310000 ( 0.308992)
- # 0.090000 0.000000 0.090000 ( 0.092182)
- # 10.500000 0.000000 10.500000 ( 10.505025)
- # 0.210000 0.000000 0.210000 ( 0.206929)
Add Comment
Please, Sign In to add comment