-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.rb
More file actions
91 lines (74 loc) · 2.52 KB
/
benchmark.rb
File metadata and controls
91 lines (74 loc) · 2.52 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
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
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
require 'simpleble'
require 'benchmark'
def run_benchmarks
puts "# SimpleBLE Benchmarks"
puts
puts "Platform: #{RUBY_PLATFORM}"
puts "Ruby Version: #{RUBY_VERSION}"
puts "SimpleBLE Version: #{SimpleBLE::VERSION}"
puts
unless SimpleBLE.bluetooth_enabled?
puts "❌ Bluetooth not available on this system"
return
end
adapters = SimpleBLE.adapters
if adapters.empty?
puts "❌ No Bluetooth adapters found"
return
end
adapter = adapters.first
puts "Using adapter: #{adapter.identifier}"
puts
# Benchmark different scan durations
scan_durations = [1000, 3000, 5000, 10000] # milliseconds
puts "## Scan Performance Benchmarks"
puts
puts "| Duration | Devices Found | Scan Time | Avg Device Discovery |"
puts "|----------|---------------|-----------|---------------------|"
scan_durations.each do |duration|
scan_time = Benchmark.realtime do
adapter.scan_for(duration)
end
devices = adapter.scan_results
device_count = devices.length
avg_discovery_time = device_count > 0 ? (scan_time * 1000 / device_count).round(1) : 0
puts "| #{duration}ms | #{device_count} | #{(scan_time * 1000).round(1)}ms | #{avg_discovery_time}ms/device |"
end
puts
puts "## Memory Usage Test"
puts
initial_memory = `ps -o rss= -p #{Process.pid}`.to_i
puts "Running 50 scan cycles (3 second scans)..."
50.times do |i|
adapter.scan_for(3000)
results = adapter.scan_results
print "." if i % 10 == 0
end
puts
final_memory = `ps -o rss= -p #{Process.pid}`.to_i
memory_diff = final_memory - initial_memory
puts "- Initial memory: #{initial_memory} KB"
puts "- Final memory: #{final_memory} KB"
puts "- Memory difference: #{memory_diff} KB"
puts "- Result: #{memory_diff.abs < 5000 ? '✅ No significant memory leak' : '⚠️ Potential memory increase'}"
puts
puts "## Test Environment"
puts
puts "- **Platform**: #{RUBY_PLATFORM}"
puts "- **Ruby Version**: #{RUBY_VERSION}"
puts "- **Architecture**: #{RbConfig::CONFIG['host_cpu']}"
puts "- **Compiler**: #{RbConfig::CONFIG['CC']}"
puts "- **OS**: #{RbConfig::CONFIG['host_os']}"
puts "- **Bluetooth Status**: #{SimpleBLE.bluetooth_enabled? ? '✅ Enabled' : '❌ Disabled'}"
puts "- **Available Adapters**: #{SimpleBLE.adapters.length}"
puts
puts "*Note: Results may vary based on BLE environment and system load.*"
end
if __FILE__ == $0
puts "Running SimpleBLE Benchmarks..."
puts "=" * 50
puts
run_benchmarks
end