Last active
August 20, 2018 23:21
-
-
Save nzajt/64eef748000b8d1e6a5ba33cd6cf88b3 to your computer and use it in GitHub Desktop.
Testing if a module or class is faster when only using one method. requires gem 'benchmark-ips' from https://github.com/evanphx/benchmark-ips
This file contains hidden or 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' | |
# test for modules | |
module TwoFer | |
# Takes name or no name and returns statement | |
def self.two_fer(name = 'you') | |
"One for #{name}, one for me." | |
end | |
end | |
class TwoFerC | |
def self.two_fer(name = 'you') | |
"One for #{name}, one for me." | |
end | |
end | |
Benchmark.ips do |x| | |
x.config(time: 5, warmup: 2) | |
x.report('Module: ') { TwoFer.two_fer('TestName') } | |
x.report('Class: ') { TwoFerC.two_fer('TestName') } | |
x.report('Module No Name:') { TwoFer.two_fer } | |
x.report('Class No Name:') { TwoFerC.two_fer } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment