Created
March 31, 2022 20:01
-
-
Save AndyDangerous/79c37314dc99b63edc92399ab85d9ea8 to your computer and use it in GitHub Desktop.
Faker vs. constant performance benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'faker' | |
require 'securerandom' | |
n = 5000 | |
Benchmark.bm(26) do |x| | |
NUM = 123.freeze | |
PASSWORD = "Password!1".freeze | |
UUID = SecureRandom.uuid.freeze | |
RAND = 1000.freeze | |
x.report("faker number:") { n.times do ; Faker::Number.number(digits: 3); end } | |
x.report("constant number:") { n.times do ; NUM; end } | |
x.report("faker password(6):") { n.times do ; Faker::Internet.password(min_length: 6); end } | |
x.report("faker password(15):") { n.times do ; Faker::Internet.password(min_length: 15); end } | |
x.report("faker password(rand(1000)):") { n.times do ; Faker::Internet.password(min_length: rand(1000)); end } | |
x.report("constant password:") { n.times do ; PASSWORD; end } | |
x.report("generate UUID:") { n.times do ; SecureRandom.uuid; end } | |
x.report("constant UUID:") { n.times do ; UUID; end } | |
x.report("rand(1000):") { n.times do ; rand(100); end } | |
x.report("constant 1000:") { n.times do ; RAND; end } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment