benchmark_time 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +20 -10
- data/lib/benchmark_time/benchmark_time.rb +5 -4
- data/lib/benchmark_time/hash_extensions.rb +2 -0
- data/lib/benchmark_time/version.rb +1 -1
- data/sample/sample_benchmark.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# BenchmarkTime
|
|
2
2
|
|
|
3
3
|
Benchmark the execution time of an arbitrary block of code. Specify concurrent
|
|
4
|
-
threads and number of execution loops
|
|
4
|
+
threads and number of execution loops.
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
|
@@ -18,26 +18,36 @@ Or install it yourself as:
|
|
|
18
18
|
$ gem install benchmark_time
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
|
+
|
|
21
22
|
require 'benchmark_time'
|
|
23
|
+
require 'bunny'
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
# Benchmark connecting and filing an item into rabbitmq with bunny
|
|
26
|
+
benchmark_time(num_threads: 10, num_loops: 5) do
|
|
24
27
|
conn = Bunny.new
|
|
25
28
|
conn.start
|
|
26
29
|
ch = conn.create_channel
|
|
27
30
|
q = ch.queue("test1")
|
|
28
|
-
q.publish(
|
|
31
|
+
q.publish('hello bunny')
|
|
29
32
|
conn.stop
|
|
30
33
|
end
|
|
31
34
|
|
|
32
35
|
->
|
|
36
|
+
--------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
Samples: 50
|
|
39
|
+
|
|
40
|
+
Min time (ms): 6
|
|
41
|
+
|
|
42
|
+
Max time (ms): 157
|
|
43
|
+
|
|
44
|
+
Average time (ms): 32.6
|
|
45
|
+
|
|
46
|
+
Standard Deviation (ms): 25.33046886777315
|
|
47
|
+
|
|
48
|
+
--------------------------------------------------------------
|
|
49
|
+
|
|
33
50
|
|
|
34
|
-
"----------------------------------------"
|
|
35
|
-
"Samples: 20"
|
|
36
|
-
"Min time: 0.059449195861816406"
|
|
37
|
-
"Max time: 0.15325689315795898"
|
|
38
|
-
"Average time: 0.10354292392730713"
|
|
39
|
-
"Standard Deviation: 0.027390028761805192"
|
|
40
|
-
"----------------------------------------"
|
|
41
51
|
|
|
42
52
|
## Contributing
|
|
43
53
|
|
|
@@ -14,13 +14,14 @@ module BenchmarkTime
|
|
|
14
14
|
# Create and run a new benchmark with output to the command line
|
|
15
15
|
# ==== Options
|
|
16
16
|
# +:work_warmup_proc:+ A proc to call for each thread. this can pre-warm connections,
|
|
17
|
-
# or perform
|
|
18
|
-
# +:
|
|
19
|
-
# +:
|
|
17
|
+
# or perform other non-timed work.
|
|
18
|
+
# +: num_threads+ Number of concurrent threads to execute the work
|
|
19
|
+
# +: num_loops+ Number of times to call the block in each execution thread.
|
|
20
20
|
def initialize(options = {}, &work_block)
|
|
21
21
|
default_options = {num_threads: 10, num_loops: 10, print_samples: true, work_warmup_proc: nil}
|
|
22
22
|
options = default_options.merge(options)
|
|
23
|
-
|
|
23
|
+
# experiment: auto-create instance variables from hash...
|
|
24
|
+
options.to_instance_variables(binding, define: :attr_reader)
|
|
24
25
|
@threads = []
|
|
25
26
|
@results = []
|
|
26
27
|
@results.extend(EnumerableStatistics)
|
data/sample/sample_benchmark.rb
CHANGED