-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark_test.rb
More file actions
41 lines (34 loc) · 1.23 KB
/
Copy pathbenchmark_test.rb
File metadata and controls
41 lines (34 loc) · 1.23 KB
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
require_relative 'lib/flow_regex'
require 'benchmark'
# 長い文字列でのテスト
def test_performance(pattern, text, iterations = 1000)
puts "Pattern: #{pattern}"
puts "Text length: #{text.length}"
puts "Iterations: #{iterations}"
puts
# Ruby版のテスト
ruby_time = Benchmark.realtime do
regex = FlowRegex.new(pattern)
iterations.times do
regex.match(text)
end
end
puts "Ruby implementation: #{(ruby_time * 1000).round(2)}ms total, #{(ruby_time * 1000 / iterations).round(4)}ms per match"
# 結果確認用に1回実行
regex = FlowRegex.new(pattern)
result = regex.match(text)
puts "Result: #{result.length} matches found"
puts
end
# テストケース1: 長い文字列での単純なパターン
puts "=== Performance Test 1: Simple Pattern ==="
long_text = "a" * 500 + "b"
test_performance("a*b", long_text, 1000)
# テストケース2: 複雑なパターン
puts "=== Performance Test 2: Complex Pattern ==="
complex_text = ("abc" * 100) + "d"
test_performance("(a|b|c)*d", complex_text, 1000)
# テストケース3: ReDoS攻撃パターン(安全性テスト)
puts "=== Performance Test 3: ReDoS Pattern ==="
redos_text = "a" * 200 + "x"
test_performance("(a+)+b", redos_text, 100)