Skip to content

Commit f7a8e72

Browse files
Benchmark load time
Using `load` instead of `require` to force load on every run. Co-Authored-By: Thiago Araujo <[email protected]>
1 parent c151298 commit f7a8e72

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

.rubocop.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ Naming/VariableNumber:
5050
Description: Use the configured style when numbering symbols, methods and variables.
5151
Enabled: false
5252

53+
Security/Eval:
54+
Description: The use of eval represents a serious security risk.
55+
Exclude:
56+
- 'lib/faker/default/json.rb'
57+
- 'benchmark/generators.rb'
58+
5359
Style/AsciiComments:
5460
Description: This cop checks for non-ascii (non-English) characters in comments.
5561
Exclude:
@@ -71,6 +77,7 @@ Style/EvalWithLocation:
7177
Description: This cop checks eval method usage. eval can receive source location metadata, that are filename and line number.
7278
Exclude:
7379
- 'lib/faker/default/json.rb'
80+
- 'benchmark/generators.rb'
7481

7582
Style/FormatStringToken:
7683
Description: This cop checks for a consistent style for named format string tokens.
@@ -102,11 +109,6 @@ Style/RegexpLiteral:
102109
- mixed
103110
AllowInnerSlashes: false
104111

105-
Security/Eval:
106-
Description: The use of eval represents a serious security risk.
107-
Exclude:
108-
- 'lib/faker/default/json.rb'
109-
110112
Style/IfUnlessModifier:
111113
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.
112114
Enabled: false

benchmark/generators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def subclass_methods(subclass)
3737
x.report("Number of generators: #{all_generators.count}") do
3838
all_generators.each { |generator| eval(generator) }
3939
end
40-
end
40+
end

benchmark/load.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
require 'benchmark/ips'
4+
require 'benchmark'
5+
6+
if defined?(Faker)
7+
raise 'faker is defined before bench'
8+
end
9+
10+
path = File.expand_path("#{File.dirname(__FILE__)}/load_faker.rb")
11+
12+
Benchmark.ips do |x|
13+
x.report('Loading Time') do
14+
system("ruby #{path}")
15+
end
16+
end

benchmark/load_faker.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
if defined?(Faker)
4+
raise 'faker is already defined...'
5+
end
6+
7+
load(File.expand_path("#{File.dirname(__FILE__)}/../lib/faker.rb"))

benchmark/load_yml_vs_json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
x.report('JSON') { JSON.load_file("#{File.dirname(__FILE__)}/../test/fixtures/locales/es-MX.json") }
1010

1111
x.compare!(order: :baseline)
12-
end
12+
end

0 commit comments

Comments
 (0)