Skip to content

Commit

Permalink
Add benchmarks for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Dec 12, 2024
1 parent 05983b1 commit 1877fa0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ gemspec name: "dotenv"
gemspec name: "dotenv-rails"

gem "railties", "~> #{ENV["RAILS_VERSION"] || "7.1"}"
gem "benchmark-ips"
gem "stackprof"

group :guard do
gem "guard-rspec"
Expand Down
15 changes: 15 additions & 0 deletions benchmark/parse_ips.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "bundler/setup"
require "dotenv"
require "benchmark/ips"
require "tempfile"

f = Tempfile.create("benchmark_ips.env")
1000.times.map { |i| f.puts "VAR_#{i}=#{i}" }
f.close

Benchmark.ips do |x|
x.report("parse, overwrite:false") { Dotenv.parse(f.path, overwrite: false) }
x.report("parse, overwrite:true") { Dotenv.parse(f.path, overwrite: true) }
end

File.unlink(f.path)
23 changes: 23 additions & 0 deletions benchmark/parse_profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "bundler/setup"
require "dotenv"
require "stackprof"
require "benchmark/ips"
require "tempfile"

f = Tempfile.create("benchmark_ips.env")
1000.times.map { |i| f.puts "VAR_#{i}=#{i}" }
f.close

profile = StackProf.run(mode: :wall, interval: 1_000) do
10_000.times do
Dotenv.parse(f.path, overwrite: false)
end
end

result = StackProf::Report.new(profile)
puts
result.print_text
puts "\n\n\n"
result.print_method(/Dotenv.parse/)

File.unlink(f.path)

0 comments on commit 1877fa0

Please sign in to comment.