Skip to content

Instantly share code, notes, and snippets.

@keymastervn
Created April 30, 2021 07:35
Show Gist options
  • Save keymastervn/a3dde8ab433c7509069f7965a704c445 to your computer and use it in GitHub Desktop.
Save keymastervn/a3dde8ab433c7509069f7965a704c445 to your computer and use it in GitHub Desktop.
Benchmark psych vs yaml
require 'benchmark/memory'
require 'memory_profiler'
require 'benchmark/ips'
require 'psych'
require 'yaml'
file = File.read('./devise.en.yml')
Benchmark.memory do |x|
x.report('psych safe_load') { Psych.safe_load file }
x.report('psych load') { Psych.load file }
x.report('yaml load') { YAML.load file }
x.compare!
end
Benchmark.ips do |x|
x.report('psych safe_load') { Psych.safe_load file }
x.report('psych load') { Psych.load file }
x.report('yaml load') { YAML.load file }
x.compare!
end
# ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]
# Calculating -------------------------------------
# psych safe_load 31.160k memsize ( 22.000k retained)
# 328.000 objects ( 223.000 retained)
# 50.000 strings ( 50.000 retained)
# psych load 28.822k memsize ( 21.254k retained)
# 294.000 objects ( 215.000 retained)
# 50.000 strings ( 50.000 retained)
# yaml load 28.822k memsize ( 21.254k retained)
# 294.000 objects ( 215.000 retained)
# 50.000 strings ( 50.000 retained)
# Comparison:
# psych load: 28822 allocated
# yaml load: 28822 allocated - same
# psych safe_load: 31160 allocated - 1.08x more
# Warming up --------------------------------------
# psych safe_load 299.000 i/100ms
# psych load 294.000 i/100ms
# yaml load 298.000 i/100ms
# Calculating -------------------------------------
# psych safe_load 2.743k (± 6.8%) i/s - 13.754k in 5.038117s
# psych load 2.726k (± 6.2%) i/s - 13.818k in 5.089565s
# yaml load 2.709k (± 5.5%) i/s - 13.708k in 5.075277s
# Comparison:
# psych safe_load: 2742.7 i/s
# psych load: 2725.8 i/s - same-ish: difference falls within error
# yaml load: 2709.0 i/s - same-ish: difference falls within error
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
en:
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
already_confirmed: "was already confirmed, please try signing in"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
devise:
failure:
resource_not_found: 'This email address was not found'
attempts_left: "Incorrect password! You have %{attempt_remaining} remaining"
already_authenticated: 'You are already signed in.'
unauthenticated: 'You need to sign in or sign up before continuing.'
unconfirmed: 'You have to confirm your account before continuing.'
locked: 'Your account is locked.'
last_attempt: 'Your next unsuccessful login attempt will lock your account'
retry: 'Oops! Try again.'
invalid: 'Unsuccessful login, please try again'
invalid_token: 'Invalid authentication token.'
timeout: 'Your session expired, please sign in again to continue.'
inactive: 'You do not have access to any organisation. Please contact [email protected] if you believe this to be a mistake.'
sessions:
signed_in: ''
signed_out: ''
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
updated_not_active: 'Your password was changed successfully.'
send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'
unlocks:
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
omniauth_callbacks:
success: 'Successfully authorized from %{kind} account.'
failure: 'Could not authorize you from %{kind} because "%{reason}".'
mailer:
confirmation_instructions:
subject: 'Confirmation instructions'
reset_password_instructions:
subject: 'Reset password instructions'
unlock_instructions:
subject: 'Unlock Instructions'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment