Skip to content

Commit

Permalink
Benchmarking loading JSON file vs YML file (#2897)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
salochara authored Mar 17, 2024
1 parent 9b4cec6 commit 6754225
Show file tree
Hide file tree
Showing 2 changed files with 2,054 additions and 9 deletions.
37 changes: 28 additions & 9 deletions tasks/benchmark.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@
require 'benchmark'
require 'faker'

desc 'Benchmarking every Faker generator'
task :benchmark do
all_methods = BenchmarkHelper.all_methods
count = all_methods.count

Benchmark.bmbm do |x|
x.report("Number of generators: #{count}") do
100.times do
all_methods.each { |method_name| eval(method_name) }
namespace :benchmark do
desc 'Benchmarking all methods'
task :all_methods do
all_methods = BenchmarkHelper.all_methods
count = all_methods.count

Benchmark.bmbm do |x|
x.report("Number of generators: #{count}") do
100.times do
all_methods.each { |method_name| eval(method_name) }
end
end
end
end

desc 'Comparing loading translations from YML vs. JSON'
task :compare_loading_yml_vs_json do
Benchmark.bmbm do |x|
x.report('YML') do
100.times do
YAML.load_file(File.expand_path("#{File.dirname(__FILE__)}/../lib/locales/es-MX.yml"))
end
end

x.report('JSON') do
100.times do
JSON.load_file("#{File.dirname(__FILE__)}/../test/fixtures/locales/es-MX.json")
end
end
end
end
Expand Down
Loading

0 comments on commit 6754225

Please sign in to comment.