File: benchmark.rake

package info (click to toggle)
libuuidtools-ruby 2.1.1-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 200 kB
  • ctags: 40
  • sloc: ruby: 860; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 875 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
task :benchmark do
  require 'lib/uuidtools'
  require 'benchmark'

  # Version 1
  result = Benchmark.measure do
    10000.times do
      UUID.timestamp_create.to_s
    end
  end
  puts "#{(10000.0 / result.real)} version 1 per second."

  # Version 3
  result = Benchmark.measure do
    10000.times do
      UUID.md5_create(UUID_URL_NAMESPACE,
        "http://www.ietf.org/rfc/rfc4122.txt").to_s
    end
  end
  puts "#{(10000.0 / result.real)} version 3 per second."

  # Version 4
  result = Benchmark.measure do
    10000.times do
      UUID.random_create.to_s
    end
  end
  puts "#{(10000.0 / result.real)} version 4 per second."

  # Version 5
  result = Benchmark.measure do
    10000.times do
      UUID.sha1_create(UUID_URL_NAMESPACE,
        "http://www.ietf.org/rfc/rfc4122.txt").to_s
    end
  end
  puts "#{(10000.0 / result.real)} version 5 per second."
end