Skip to content

Instantly share code, notes, and snippets.

@cianmce
Last active May 27, 2018 20:23
Show Gist options
  • Save cianmce/db425cb3d080cfc948c478fccd72dd3d to your computer and use it in GitHub Desktop.
Save cianmce/db425cb3d080cfc948c478fccd72dd3d to your computer and use it in GitHub Desktop.
DOS fnando/password_strength
require 'securerandom'
require 'password_strength'
require 'benchmark'
def random_string(len)
SecureRandom.base64(len)[0...len]
end
Benchmark.bm do |x|
30.times do |n|
len = (n**4).to_i
pass = random_string(len)
x.report("Len: #{len}".ljust(13, ' ')) { PasswordStrength.test("username", pass) }
end
end
user system total real
Len: 0 0.000000 0.000000 0.000000 ( 0.002083)
Len: 1 0.000000 0.000000 0.000000 ( 0.000051)
Len: 16 0.000000 0.000000 0.000000 ( 0.000332)
Len: 81 0.000000 0.000000 0.000000 ( 0.001429)
Len: 256 0.000000 0.010000 0.010000 ( 0.005734)
Len: 625 0.020000 0.000000 0.020000 ( 0.020888)
Len: 1296 0.080000 0.000000 0.080000 ( 0.078562)
Len: 2401 0.220000 0.000000 0.220000 ( 0.223002)
Len: 4096 0.570000 0.000000 0.570000 ( 0.570973)
Len: 6561 1.310000 0.010000 1.320000 ( 1.322156)
Len: 10000 2.810000 0.010000 2.820000 ( 2.825737)
Len: 14641 6.410000 0.030000 6.440000 ( 6.472998)
Len: 20736 12.350000 0.060000 12.410000 ( 12.479648)
Len: 28561 33.500000 0.260000 33.760000 ( 34.125364)
Len: 38416 62.250000 0.370000 62.620000 ( 63.056908)
Len: 50625 123.370000 1.150000 124.520000 (126.204006)
Len: 65536 246.240000 2.800000 249.040000 (258.125013)
Len: 83521 387.200000 2.680000 389.880000 (393.897267)
Len: 104976 593.270000 3.540000 596.810000 (605.670005)
Len: 130321 975.180000 10.110000 985.290000 (1034.482099)
Len: 160000 1387.81000 9.150000 1396.96000 (2450.387897)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment