Last active
February 8, 2018 02:55
-
-
Save youroff/dc4f0ff71083acf6c180ec33f3c52881 to your computer and use it in GitHub Desktop.
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' | |
class Sqr | |
def initialize(xs) | |
@xs = xs | |
end | |
def run | |
puts "INLINE" | |
puts Benchmark.measure { @xs.map { |x| x * x } } | |
puts "INSTANCE" | |
puts Benchmark.measure { @xs.map { |x| sqr(x) } } | |
puts "CLASS" | |
puts Benchmark.measure { @xs.map { |x| self.class.sqr(x) } } | |
end | |
def sqr(x) | |
x * x | |
end | |
def self.sqr(x) | |
x * x | |
end | |
end | |
Sqr.new(0..100000000).run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment