Skip to content

Commit 6f04b9f

Browse files
committed
Added benchmark test.
Added a benchmark test to check future implementations of the algorithm
1 parent 975f2d0 commit 6f04b9f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

script/benchmark

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -e
4+
set -u
5+
6+
ruby -Ilib/ spec/performance_hex_values_test.rb

spec/performance_hex_values_test.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'minitest/autorun'
2+
require 'minitest/benchmark'
3+
4+
require 'hex_values'
5+
6+
# This test is only useful to compare differents implementations of
7+
# the algorithm used to transformt floats to hex and vicecersa.
8+
class BenchHexValues < MiniTest::Unit::TestCase
9+
def bench_float_to_hex
10+
assert_performance_linear 0.9999 do |n|
11+
n.times do
12+
(98789879890.87).to_hex #O(1)
13+
end
14+
end
15+
end
16+
17+
def bench_integer_to_hex
18+
assert_performance_linear 0.999 do |n|
19+
n.times do
20+
9878987608.to_hex #O(1)
21+
end
22+
end
23+
end
24+
25+
def bench_hex_to_float
26+
assert_performance_linear 0.9999 do |n|
27+
n.times do
28+
"5f2f9e39.42".to_float #O(1)
29+
end
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)