README.md in rgot-0.0.4 vs README.md in rgot-0.0.5
- old
+ new
@@ -81,10 +81,16 @@
end
end
end
```
+```
+$ rgot foo_test.rb --bench .
+benchmark_something 14400000 81.392 ns/op
+ok FooTest 2.782s
+```
+
`b.n` is automatically adjusted.
## Example
Rgot's example feature is the best and if you want to write the sample code of your library.
@@ -139,38 +145,46 @@
But all file should be have one module (like golang package name).
```ruby
module XxxTest
+ # ...
end
```
## Method name
-Method name should be set 'test_*' for testing.
+Method name should be set `test_*` for testing.
-And benchmark method should be set 'benchmark_*'.
+And benchmark method should be set `benchmark_*`.
+And example method should be set `example_*`.
+
```ruby
module XxxTest
def test_any_name(t)
end
def benchmark_any_name(b)
end
+
+ def example_any_name
+ end
end
```
-# Command
+# Command line interface
```
$ rgot -h
Usage: rgot [options]
-v, --verbose log all tests
--bench [regexp] benchmark
--benchtime [sec] benchmark running time
--timeout [sec] set timeout sec to testing
+ --cpu [count,...] set cpu counts of comma splited
+ --thread [count,...] set thread counts of comma splited
--require [path] load some code before running
--load-path [path] Specify $LOAD_PATH directory
```
## Basic
@@ -215,10 +229,45 @@
`.` means match all string for regexp.
Set `someone` if you only run benchmark to match `someone` method.(e.g. benchmark_someone_1)
+### Parallel benchmark
+
+Benchmark for parallel performance.
+
+`--cpu` option set process counts (default 1).
+
+And `--thread` option set thread counts (default 1).
+
+Benchmark fork, run and report each by process counts.
+
+(**process** and **thread** means ruby/linux process)
+
+```ruby
+module FooTest
+ def benchmark_any_func(b)
+ b.run_parallel do |pb|
+ # pb is instance of Rgot::PB
+ # call some time by b.n
+ while pb.next
+ some_func()
+ end
+ end
+ end
+end
+```
+
+```
+$ rgot foo_test.rb --bench . --cpu=2,4 --thread=2,4
+benchmark_any_func-2(2) 40 13363604.899 ns/op
+benchmark_any_func-2(4) 160 7125845.113 ns/op
+benchmark_any_func-4(2) 160 7224815.534 ns/op
+benchmark_any_func-4(4) 320 3652431.962 ns/op
+ok FooTest 3.061s
+```
+
## Timeout
```
$ rgot target_file_test.rb --timeout 3
```
@@ -320,25 +369,65 @@
Automatic number calculated by running time.
Recommend to this idiom.
```ruby
-def benchmark_someone(b)
+def benchmark_something(b)
i = 0
while i < b.n
- someone()
+ something()
i += 1
end
end
```
## Rgot::B#reset_timer
Reset benchmark timer
+```ruby
+def benchmark_something(b)
+ obj = heavy_prepare_method()
+ b.reset_timer # you can ignore time of havy_prepare_method()
+ i = 0
+ while i < b.n
+ obj.something()
+ i += 1
+ end
+end
+```
+
## Rgot::B#start_timer
Start benchmark timer
## Rgot::B#stop_timer
Stop benchmark timer
+
+## Rgot::B#run_parallel
+
+Start parallel benchmark using `fork` and `Thread.new`.
+
+This method should be call with block.
+
+The block argument is instance of Rgot::PB.
+
+# Rgot::PB (Parallel Benchmark)
+
+## Rgot::PB#next
+
+Should be call this when parallel benchmark.
+
+Repeat while return false.
+
+Recommend this idiom.
+
+```ruby
+def benchmark_foo(b)
+ b.run_parallel do |pb|
+ while pb.next
+ some_func()
+ end
+ end
+end
+```