Skip to content

Commit 6754225

Browse files
authored
Benchmarking loading JSON file vs YML file (#2897)
* Fix#2851 Add namespace to benchmark rake task to add other tasks * [Fix:2851] Add rake task to compare loading translation times with JSON vs YML * [Fix:2851] Add es-MX.json file * [Fix:2851] Use JSON.load_file method in benchmark since that is the method that i18n is using * [Fix:2851] Address PR comments. Moved JSON file into test directory
1 parent 9b4cec6 commit 6754225

File tree

2 files changed

+2054
-9
lines changed

2 files changed

+2054
-9
lines changed

tasks/benchmark.rake

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,34 @@
55
require 'benchmark'
66
require 'faker'
77

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) }
8+
namespace :benchmark do
9+
desc 'Benchmarking all methods'
10+
task :all_methods do
11+
all_methods = BenchmarkHelper.all_methods
12+
count = all_methods.count
13+
14+
Benchmark.bmbm do |x|
15+
x.report("Number of generators: #{count}") do
16+
100.times do
17+
all_methods.each { |method_name| eval(method_name) }
18+
end
19+
end
20+
end
21+
end
22+
23+
desc 'Comparing loading translations from YML vs. JSON'
24+
task :compare_loading_yml_vs_json do
25+
Benchmark.bmbm do |x|
26+
x.report('YML') do
27+
100.times do
28+
YAML.load_file(File.expand_path("#{File.dirname(__FILE__)}/../lib/locales/es-MX.yml"))
29+
end
30+
end
31+
32+
x.report('JSON') do
33+
100.times do
34+
JSON.load_file("#{File.dirname(__FILE__)}/../test/fixtures/locales/es-MX.json")
35+
end
1736
end
1837
end
1938
end

0 commit comments

Comments
 (0)