Module: RubyVolt::Helper

Defined in:
lib/ruby_volt/helper.rb

Class Method Summary collapse

Class Method Details

.benchmark(cycle = 1000, &block) ⇒ Object



4
5
6
7
8
9
# File 'lib/ruby_volt/helper.rb', line 4

def self.benchmark(cycle = 1000, &block)
  start = Time.now
  cycle.times { yield }
  spend = Time.now - start
  puts "Execution time: #{spend} sec. #{(cycle/spend).round(2)} TPS."
end

.uniq_bytes(length = 8) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_volt/helper.rb', line 11

def self.uniq_bytes(length = 8)
  bytes = ::String.new(:capacity => length)
  bytes <<
  if length > 0
    nsec = Time.now.nsec
    int = DataType::Integer.pack(nsec)
    if length/2 < 4
      int.b[-length/2..-1]
    else
      int
    end
  else
    ::String.new
  end
  bytes << SecureRandom.random_bytes(length - bytes.bytesize)
end