-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add benchmark script #14
Conversation
Can be executed by `bundle exec ruby benchmark.rb` or `bundle exec rake benchmark`.
require "benchmark/ips" | ||
require "benchmark/memory" | ||
|
||
puts "```ruby" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this puts
stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just copy the full output, paste it in GitHub, for example — that's all.
Example:
bundle exec rake benchmark
# frozen_string_literal: true
require "bundler/setup"
Bundler.setup
require "benchmark"
require "benchmark/ips"
require "benchmark/memory"
puts "```ruby"
puts File.read(__FILE__)
puts "```"
puts
puts "### Output"
puts
puts "```"
require_relative "lib/memery"
class Foo
class << self
include Memery
def base_find(char)
("a".."k").find { |letter| letter == char }
end
memoize def find_new(char)
base_find(char)
end
end
end
def test_memery
Foo.find_new("d")
end
Benchmark.ips do |x|
x.report("test_memery") { test_memery }
end
Benchmark.memory do |x|
x.report("test_memery") { 100.times { test_memery } }
end
puts "```"
Output
Warming up --------------------------------------
test_memery 33.193k i/100ms
Calculating -------------------------------------
test_memery 386.577k (± 2.4%) i/s - 1.958M in 5.069159s
Calculating -------------------------------------
test_memery 16.000k memsize ( 0.000 retained)
400.000 objects ( 0.000 retained)
3.000 strings ( 0.000 retained)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bench script itself and bench results in one place, Markdown-formatted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Can be executed by
bundle exec ruby benchmark.rb
orbundle exec rake benchmark
.