Created
December 14, 2018 02:54
-
-
Save packrat386/0f7603ceb913b579445e8b0faee30f65 to your computer and use it in GitHub Desktop.
Some people manage to do everything the hard way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
SIZE = 10 | |
Benchmark.ips do |x| | |
x.report('insane') do | |
[0].cycle.take(SIZE) | |
end | |
x.report('sane') do | |
Array.new(SIZE, 0) | |
end | |
x.report('alternative') do | |
[0] * SIZE | |
end | |
end | |
=begin | |
ruby rees.rb | |
Warming up -------------------------------------- | |
insane 62.407k i/100ms | |
sane 140.605k i/100ms | |
alternative 132.611k i/100ms | |
Calculating ------------------------------------- | |
insane 831.289k (± 4.1%) i/s - 4.181M in 5.038624s | |
sane 2.723M (± 5.1%) i/s - 13.639M in 5.021281s | |
alternative 2.289M (± 4.4%) i/s - 11.537M in 5.049794s | |
=end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/memory' | |
SIZE = 10 | |
Benchmark.memory do |x| | |
x.report('insane') do | |
[0].cycle.take(SIZE) | |
end | |
x.report('sane') do | |
Array.new(SIZE, 0) | |
end | |
x.report('alternative') do | |
[0] * SIZE | |
end | |
end | |
=begin | |
ruby rees_mem.rb | |
Calculating ------------------------------------- | |
insane 288.000 memsize ( 0.000 retained) | |
3.000 objects ( 0.000 retained) | |
0.000 strings ( 0.000 retained) | |
sane 120.000 memsize ( 0.000 retained) | |
1.000 objects ( 0.000 retained) | |
0.000 strings ( 0.000 retained) | |
alternative 160.000 memsize ( 0.000 retained) | |
2.000 objects ( 0.000 retained) | |
0.000 strings ( 0.000 retained) | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment