2019-06-25 21:40:58 +02:00
|
|
|
require "../src/cox"
|
2019-06-27 18:34:23 +02:00
|
|
|
require "tallboy"
|
2019-06-25 21:40:58 +02:00
|
|
|
|
|
|
|
if ARGV.empty?
|
|
|
|
puts "Help select Pwhash ops/mem limits for your application."
|
|
|
|
puts "Usage: #{PROGRAM_NAME} time_min [time_max] [mem_max]"
|
|
|
|
puts "\ttime is in seconds"
|
2019-06-27 17:03:33 +02:00
|
|
|
puts "\tmem is in bytes"
|
2019-06-25 21:40:58 +02:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
time_min = ARGV.shift?.try &.to_f || 0.1
|
|
|
|
time_limit = if t = ARGV.shift?
|
|
|
|
t.to_f
|
|
|
|
else
|
|
|
|
time_min * 4
|
|
|
|
end
|
2019-06-27 17:03:33 +02:00
|
|
|
mem_limit = (ARGV.shift?.try &.to_i || (Cox::Pwhash::MEMLIMIT_MAX)).to_u64
|
2019-06-25 21:40:58 +02:00
|
|
|
pwhash = Cox::Pwhash.new
|
|
|
|
pass = "1234"
|
|
|
|
|
2019-06-28 02:20:02 +02:00
|
|
|
# data = Array(Array({UInt64, UInt64, Float64})).new
|
2019-06-27 18:34:23 +02:00
|
|
|
header = [" "]
|
|
|
|
data = [header]
|
|
|
|
|
|
|
|
def bytes_str(b)
|
|
|
|
suffix = if b >= 1024*1024
|
2019-06-28 02:20:02 +02:00
|
|
|
b /= (1024*1024)
|
|
|
|
"M"
|
|
|
|
elsif b >= 1024
|
|
|
|
b = b / 1024
|
|
|
|
"K"
|
|
|
|
else
|
|
|
|
""
|
|
|
|
end
|
2019-06-27 18:34:23 +02:00
|
|
|
"%5d#{suffix}" % b
|
|
|
|
end
|
|
|
|
|
2019-06-25 21:40:58 +02:00
|
|
|
pwhash.memlimit = Cox::Pwhash::MEMLIMIT_MIN
|
|
|
|
loop do
|
|
|
|
pwhash.opslimit = Cox::Pwhash::OPSLIMIT_MIN
|
2019-06-27 18:34:23 +02:00
|
|
|
row = ["%5dK" % (pwhash.memlimit / 1024)]
|
|
|
|
data << row
|
2019-06-25 21:40:58 +02:00
|
|
|
|
|
|
|
loop do
|
|
|
|
# p pwhash
|
2019-06-27 17:03:33 +02:00
|
|
|
t = Time.measure { pwhash.store pass }.to_f
|
2019-06-27 18:34:23 +02:00
|
|
|
ostr = "%7d" % pwhash.opslimit
|
|
|
|
header << ostr if data.size == 2
|
|
|
|
if t >= time_min
|
|
|
|
mstr = bytes_str pwhash.memlimit
|
2019-06-28 02:20:02 +02:00
|
|
|
# mstr = "%5dK" % (pwhash.memlimit / 1024)
|
2019-06-27 18:34:23 +02:00
|
|
|
tstr = "%6.3fs" % t
|
|
|
|
row << tstr
|
|
|
|
s = String.build do |sb|
|
|
|
|
sb << "mem_limit "
|
|
|
|
sb << mstr
|
|
|
|
sb << " ops_limit "
|
|
|
|
sb << ostr
|
|
|
|
sb << " "
|
|
|
|
sb << tstr
|
|
|
|
end
|
|
|
|
puts s
|
|
|
|
else
|
|
|
|
row << " "
|
2019-06-25 21:40:58 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
break if t >= time_limit
|
2019-06-27 18:34:23 +02:00
|
|
|
pwhash.opslimit *= 4
|
2019-06-25 21:40:58 +02:00
|
|
|
end
|
2019-06-27 18:34:23 +02:00
|
|
|
row << "" # puts | on the end
|
2019-06-25 21:40:58 +02:00
|
|
|
puts ""
|
|
|
|
|
|
|
|
break if pwhash.memlimit >= mem_limit
|
2019-06-27 17:03:33 +02:00
|
|
|
break if pwhash.opslimit == Cox::Pwhash::OPSLIMIT_MIN # Couldn't get past 1 iteration before going over time.
|
2019-06-27 18:34:23 +02:00
|
|
|
pwhash.memlimit *= 4
|
2019-06-25 21:40:58 +02:00
|
|
|
end
|
2019-06-28 02:20:02 +02:00
|
|
|
# header << "Ops limit"
|
2019-06-27 18:34:23 +02:00
|
|
|
data << ["Memory"]
|
2019-06-25 21:40:58 +02:00
|
|
|
|
2019-06-27 18:34:23 +02:00
|
|
|
# Quick n dirty sparse table.
|
|
|
|
puts "Ops Limit --->"
|
|
|
|
data.each do |row|
|
|
|
|
puts row.join(" | ")
|
|
|
|
end
|