File: benchmark_simple.rb

package info (click to toggle)
ruby-rqrcode-core 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 520 kB
  • sloc: ruby: 2,289; makefile: 4; sh: 4
file content (112 lines) | stat: -rw-r--r-- 2,548 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "rqrcode_core"
require "benchmark"

puts "=" * 80
puts "RQRCode Core - Simple Benchmark"
puts "=" * 80
puts "Ruby: #{RUBY_VERSION} (#{RUBY_PLATFORM})"
puts "ARCH_BITS: #{RQRCodeCore::QRUtil::ARCH_BITS}"
puts "=" * 80
puts

# Quick benchmark with few iterations for development
# For detailed analysis, use benchmark_performance.rb
ITERATIONS = 10

Benchmark.bm(35) do |x|
  x.report("Small (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("hello")
    end
  end

  x.report("Small (v1) with rendering:") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("hello").to_s
    end
  end

  x.report("URL (v5):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("https://github.com/whomwah/rqrcode_core")
    end
  end

  x.report("URL (v5) with rendering:") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("https://github.com/whomwah/rqrcode_core").to_s
    end
  end

  x.report("Large text (v24):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("a" * 500)
    end
  end

  x.report("Large text (v24) with rendering:") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("a" * 500).to_s
    end
  end

  x.report("Numeric mode (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("1234567890", mode: :number)
    end
  end

  x.report("Alphanumeric mode (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("HELLO WORLD", mode: :alphanumeric)
    end
  end

  x.report("Byte mode (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("hello world", mode: :byte_8bit)
    end
  end

  x.report("Error correction :l (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("hello", level: :l)
    end
  end

  x.report("Error correction :m (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("hello", level: :m)
    end
  end

  x.report("Error correction :q (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("hello", level: :q)
    end
  end

  x.report("Error correction :h (v1):") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new("hello", level: :h)
    end
  end

  x.report("Multi-segment encoding:") do
    ITERATIONS.times do
      RQRCodeCore::QRCode.new([
        {data: "hello", mode: :byte_8bit},
        {data: "WORLD123", mode: :alphanumeric},
        {data: "9876543210", mode: :number}
      ])
    end
  end
end

puts
puts "=" * 80
puts "Benchmark complete! (#{ITERATIONS} iterations per test)"
puts "=" * 80