Skip to content
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

Merged
merged 2 commits into from
Aug 16, 2019
Merged

Conversation

AlexWayfer
Copy link
Contributor

Can be executed by bundle exec ruby benchmark.rb or bundle exec rake benchmark.

Can be executed by `bundle exec ruby benchmark.rb` or `bundle exec rake benchmark`.
@coveralls
Copy link

coveralls commented Aug 16, 2019

Pull Request Test Coverage Report for Build 45

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 43: 0.0%
Covered Lines: 186
Relevant Lines: 186

💛 - Coveralls

require "benchmark/ips"
require "benchmark/memory"

puts "```ruby"
Copy link
Owner

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?

Copy link
Contributor Author

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)

Copy link
Contributor Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tycooon tycooon merged commit 7cb68b9 into tycooon:master Aug 16, 2019
@AlexWayfer AlexWayfer deleted the add_benchmark_script branch August 16, 2019 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants