-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Benchmark revamp + run benchmark as part of CI #3176
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
Changes from all commits
f09c7b1
a109a55
07769e9
8714ae3
7745001
766c36c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Bench | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| name: Benchmarks | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: '3.4' | ||
| - name: Install dependencies | ||
| run: bundle install | ||
|
|
||
| - name: Generators | ||
| run: RUBYOPT="-W0" bundle exec ruby benchmark/generators.rb | ||
| - name: Require | ||
| run: RUBYOPT="-W0" bundle exec ruby benchmark/require.rb | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||||||||||||||||
| # frozen_string_literal: true | ||||||||||||||||||
|
|
||||||||||||||||||
stefannibrasil marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
| require 'benchmark/ips' | ||||||||||||||||||
| require 'faker' | ||||||||||||||||||
|
|
||||||||||||||||||
| def generators | ||||||||||||||||||
| constants.flat_map do |klass| | ||||||||||||||||||
| subclass_methods(klass) | ||||||||||||||||||
| end | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| def constants | ||||||||||||||||||
| Faker.constants.delete_if do |subclass| | ||||||||||||||||||
| %i[ | ||||||||||||||||||
| Base | ||||||||||||||||||
| Cat | ||||||||||||||||||
| Char | ||||||||||||||||||
| Base58 | ||||||||||||||||||
| Config | ||||||||||||||||||
| Date | ||||||||||||||||||
| Deprecator | ||||||||||||||||||
| Dog | ||||||||||||||||||
| Religion | ||||||||||||||||||
| Time | ||||||||||||||||||
| VERSION | ||||||||||||||||||
| ].include?(subclass) | ||||||||||||||||||
| end.sort | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| def subclass_methods(subclass) | ||||||||||||||||||
| klass = Faker.const_get(subclass) | ||||||||||||||||||
|
|
||||||||||||||||||
| public_methods = klass.public_methods(false) - Faker::Base.public_methods(false) | ||||||||||||||||||
|
|
||||||||||||||||||
| public_methods.sort.map do |method| | ||||||||||||||||||
| [klass, method] | ||||||||||||||||||
| end | ||||||||||||||||||
| end | ||||||||||||||||||
thdaraujo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
|
||||||||||||||||||
| all_generators = generators | ||||||||||||||||||
|
|
||||||||||||||||||
| Benchmark.ips do |x| | ||||||||||||||||||
| x.report("Number of generators: #{all_generators.count}") do | ||||||||||||||||||
| all_generators.each { |klass, generator| klass.send(generator) } | ||||||||||||||||||
| end | ||||||||||||||||||
|
Comment on lines
43
to
45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should build the list of generators outside so that we're only benchmarking generator execution
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks! Changed in 8714ae3 |
||||||||||||||||||
| end | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'benchmark' | ||
|
|
||
| ms = Benchmark.realtime do | ||
| require 'faker' | ||
| end * 1000 | ||
|
|
||
| puts "took #{ms}ms to load" |
This file was deleted.
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.
maybe
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.
Fair enough. I also added an extra permission for pull requests, and for the tests workflow as well in 07769e9