compare_time 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/compare_time.rb +46 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cd281877ea1c276efb48cdd1a5ad1bed518b9a81
|
4
|
+
data.tar.gz: 3295ae934bb31b6f0179298eab1e60e7cfba863c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb33aa21e2d9c5feb95d9f44286899fab08cc7e5cb2e55a5a11204a535c211820453cb88c3dbd07b56cc954e8b877f4101ded839d5a17ffb12e0ed9dd9196bf1
|
7
|
+
data.tar.gz: 4c59732bf2dbf6ef11b5e0d6d8a0776e2ee623d0b7df8484d0aa7e180faab0bc3c905c027d894fdf53c5f6ba867a91f6283587ade6191f2fdd1cc037cb29a8b2
|
data/lib/compare_time.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
# CompareTime.new.compare(:whatever_name_you_want) {
|
5
|
+
# ...
|
6
|
+
# }.with(:whatever_name_you_want2) {
|
7
|
+
# ...
|
8
|
+
# }.print_results
|
9
|
+
|
10
|
+
class CompareTime
|
11
|
+
attr_reader :benchmarks
|
12
|
+
|
13
|
+
def initialize()
|
14
|
+
# add how many times
|
15
|
+
@benchmarks = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def compare(symbol, &block)
|
19
|
+
execute_and_save(symbol, block)
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def results
|
24
|
+
@benchmarks.sort_by(&:last).map do |arr|
|
25
|
+
"#{arr[0]}: #{'%.10f' % arr[1]}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def print_results
|
30
|
+
puts results[0].colorize(:green)
|
31
|
+
|
32
|
+
results.drop(1).each do |res|
|
33
|
+
puts res
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
alias_method :with, :compare
|
38
|
+
|
39
|
+
private def execute_and_save(symbol, block)
|
40
|
+
original_stdout = $stdout
|
41
|
+
$stdout = StringIO.new
|
42
|
+
@benchmarks[symbol] = Benchmark.realtime(&block)
|
43
|
+
ensure
|
44
|
+
$stdout = original_stdout
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compare_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bartek Gladecki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Compare execution times for given blocks, right?
|
14
|
+
email: bgladecki@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/compare_time.rb
|
20
|
+
homepage: http://rubygems.org/gems/compare_time
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.6.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Compare execution times for given blocks
|
44
|
+
test_files: []
|