Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Bench

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe

Suggested change
permissions:
contents: read

Copy link
Contributor Author

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

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

5 changes: 4 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:

permissions:
contents: read
pull-requests: read

jobs:
lint:
Expand Down Expand Up @@ -53,7 +54,9 @@ jobs:
ruby-version: ${{ matrix.ruby }}

- name: Install dependencies
run: bundle install
run: |
bundle config --without benchmark
bundle install

- name: Run tests
run: bundle exec rake test
10 changes: 5 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ Naming/VariableNumber:
Description: Use the configured style when numbering symbols, methods and variables.
Enabled: false

Security/Eval:
Description: The use of eval represents a serious security risk.
Exclude:
- 'lib/faker/default/json.rb'

Style/AsciiComments:
Description: This cop checks for non-ascii (non-English) characters in comments.
Exclude:
Expand Down Expand Up @@ -102,11 +107,6 @@ Style/RegexpLiteral:
- mixed
AllowInnerSlashes: false

Security/Eval:
Description: The use of eval represents a serious security risk.
Exclude:
- 'lib/faker/default/json.rb'

Style/IfUnlessModifier:
Description: Checks for `if` and `unless` statements that would fit on one line if written as modifier `if`/`unless`. The cop also checks for modifier `if`/`unless` lines that exceed the maximum line length.
Enabled: false
Expand Down
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in faker.gemspec
gemspec

gem 'benchmark'
gem 'irb'
gem 'minitest', '5.26.1'
gem 'pry', '0.16.0'
Expand All @@ -18,3 +17,8 @@ gem 'simplecov', '0.22.0'
gem 'test-unit', '3.7.7'
gem 'timecop', '0.9.10'
gem 'yard', '0.9.38'

group :benchmark do
gem 'benchmark'
gem 'benchmark-ips'
end
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GEM
specs:
ast (2.4.3)
benchmark (0.5.0)
benchmark-ips (2.14.0)
coderay (1.1.3)
concurrent-ruby (1.3.6)
date (3.5.1)
Expand Down Expand Up @@ -96,6 +97,7 @@ PLATFORMS

DEPENDENCIES
benchmark
benchmark-ips
faker!
irb
minitest (= 5.26.1)
Expand Down
46 changes: 46 additions & 0 deletions benchmark/generators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

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

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
end
9 changes: 9 additions & 0 deletions benchmark/require.rb
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"
62 changes: 0 additions & 62 deletions tasks/benchmark.rake

This file was deleted.

Loading