File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ source 'https://rubygems.org'
55# Specify your gem's dependencies in faker.gemspec
66gemspec
77
8+ gem 'benchmark'
89gem 'minitest' , '5.20.0'
910gem 'pry' , '0.14.2'
1011gem 'rake' , '13.1.0'
Original file line number Diff line number Diff line change 88 remote: https://rubygems.org/
99 specs:
1010 ast (2.4.2 )
11+ benchmark (0.3.0 )
1112 coderay (1.1.3 )
1213 concurrent-ruby (1.2.2 )
1314 docile (1.4.0 )
@@ -64,6 +65,7 @@ PLATFORMS
6465 ruby
6566
6667DEPENDENCIES
68+ benchmark
6769 faker !
6870 minitest (= 5.20.0 )
6971 pry (= 0.14.2 )
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # rubocop:disable Security/Eval,Style/EvalWithLocation
4+
5+ require 'benchmark'
6+ require 'faker'
7+
8+ desc 'Benchmarking every Faker generator'
9+ task :benchmark do
10+ all_methods = BenchmarkHelper . all_methods
11+ count = all_methods . count
12+
13+ Benchmark . bmbm do |x |
14+ x . report ( "Number of generators: #{ count } " ) do
15+ 100 . times do
16+ all_methods . each { |method_name | eval ( method_name ) }
17+ end
18+ end
19+ end
20+ end
21+
22+ class BenchmarkHelper
23+ class << self
24+ def all_methods
25+ subclasses . map do |subclass |
26+ subclass_methods ( subclass ) . flatten
27+ end . flatten . sort
28+ end
29+
30+ def subclasses
31+ Faker . constants . delete_if do |subclass |
32+ %i[ Base Bank Books Cat Char Base58 ChileRut CLI Config Creature Date Dog DragonBall Dota ElderScrolls Fallout Games GamesHalfLife HeroesOfTheStorm Internet JapaneseMedia LeagueOfLegends Movies Myst Overwatch OnePiece Pokemon Religion Sports SwordArtOnline TvShows Time VERSION Witcher WorldOfWarcraft Zelda ] . include? ( subclass )
33+ end . sort
34+ end
35+
36+ def subclass_methods ( subclass )
37+ eval ( "Faker::#{ subclass } .public_methods(false) - Faker::Base.public_methods(false)" ) . sort . map do |method |
38+ "Faker::#{ subclass } .#{ method } "
39+ end . sort
40+ end
41+ end
42+ end
43+ # rubocop:enable Security/Eval,Style/EvalWithLocation
You can’t perform that action at this time.
0 commit comments