benchparser 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 552a3e1a134a557ecda76faf8080d2518e3f8222
4
- data.tar.gz: 33eb890e1a69cb8ef8a57dae2b91a3bdd770977a
3
+ metadata.gz: d5146fbb6371f43e64a473a8725526782ec133f9
4
+ data.tar.gz: d5c64740baabb51dc437fce3fe02cf7df26ba1fb
5
5
  SHA512:
6
- metadata.gz: dddd7e03efe650d96cec71a5fabcf23a5cdecf7743a3a3776a49b9df6b2f6972e2478ad8d75196e259f06cdc672bfa182e0156a91d7e0e7d5ba6a15ccf86f4f0
7
- data.tar.gz: cbf57d8f9a661ce358ffdf39c517869f15734e921a098f5aeb2bebadd93361da8b07ba2eadff92f3bc71b40d0e972f533cae248c1c73edd7d973c03a91afe9f4
6
+ metadata.gz: b69037f54ace08d33b265d6e4dd31254b6223a07792290b352f53ecfd603df2c7f2388bee59816fd97a0d5c51e5e2dff3c1531f5349edafe3426fe29c8fe14a5
7
+ data.tar.gz: 5bf6ddbb7d9078637b1cb6279582be2fb76146732ee43874f64870d834e4fb59662d65e05c8c49bdc89fc23a8c60b453cd880831cac2e33253207abc7b976d9d
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Build Status](https://travis-ci.com/drish/benchparser.svg?branch=master)](https://travis-ci.com/drish/benchparser)
2
+ [![Gem Version](https://badge.fury.io/rb/benchparser.svg)](https://badge.fury.io/rb/benchparser)
2
3
 
3
4
  # Benchparser
4
5
 
@@ -13,7 +14,7 @@ gem 'benchparser'
13
14
 
14
15
  ### Usage
15
16
 
16
- Golang benchmark standard output
17
+ Golang benchmark standard output
17
18
 
18
19
  ```text
19
20
  goos: darwin
@@ -28,10 +29,10 @@ ok github.com/drish/parser 9.960s
28
29
  ```ruby
29
30
  require 'benchparser'
30
31
 
31
- parsed = Bp.parse(data)
32
+ parsed = Bp.parse(:go, data)
32
33
  parsed.language # go
33
- parsed.goos # darwin
34
- parsed.pkg # darwin
34
+ parsed.configs[:goos] # darwin
35
+ parsed.configs[:pkg] # darwin
35
36
  parsed.functions.count # 1
36
37
  parsed.functions.first[:iterations] # 1000000000
37
38
  parsed.functions.first[:ns_op] # 2.48
@@ -44,6 +45,7 @@ parsed.functions.first[:allocs_op] # 0
44
45
 
45
46
  - [ ] Ruby [benchmark](https://ruby-doc.org/stdlib-2.5.0/libdoc/benchmark/rdoc/)
46
47
  - [ ] Python [timeit](https://docs.python.org/2/library/timeit.html)
48
+ - [ ] Rust [Criterion](https://github.com/bheisler/criterion.rs)
47
49
 
48
50
  ## Contributing
49
51
 
data/lib/benchparser.rb CHANGED
@@ -9,9 +9,19 @@ require "benchparser/parsers/ts"
9
9
 
10
10
  module Benchparser
11
11
  class ParseError < StandardError; end
12
+ class UnsupportedLang < StandardError; end
12
13
 
13
14
  class << self
14
- def parse
15
+
16
+ def parse(lang, data)
17
+
18
+ raise UnsupportedLang if lang.nil?
19
+ case lang.to_sym
20
+ when :go
21
+ Benchparser::Parsers::Go.parse(data)
22
+ else
23
+ raise UnsupportedLang.new("unsupported language #{lang.to_s}")
24
+ end
15
25
  end
16
26
  end
17
27
  end
@@ -1,39 +1,46 @@
1
1
  module Benchparser
2
2
  module Parsers
3
3
  class Go < Benchparser::Result
4
- attr_accessor :goos, :goarch, :pkg
5
4
 
6
5
  def initialize(raw_data)
7
6
  super(language: 'go')
8
7
  lines = raw_data.split("\n")
8
+
9
9
  lines.each_with_index do |line, index|
10
- case index
11
- when 0
12
- @goos = line.sub('goos: ', '') if line.include?('goos')
13
- when 1
14
- @goarch = line.sub('goarch: ', '') if line.include?('goarch')
15
- when 2
16
- @pkg = line.sub('pkg: ', '') if line.include?('pkg')
17
- else
10
+
11
+ return if line.include?('PASS') or line.include?('ok')
12
+
13
+ if line.start_with?('Benchmark')
18
14
  parsed_line = parse_function(line)
19
15
  @functions << parsed_line unless parsed_line.nil?
16
+ else
17
+ config = line.split(':')
18
+ @configs[config.first.to_sym] = config[1].strip unless config.first.nil? or config[1].nil?
20
19
  end
21
20
  end
22
21
  end
23
22
 
23
+ # finds the metric by calculating the index of the metric - 1
24
+ def get_metric(line_array, metric)
25
+ metric_index = line_array.find_index(metric)
26
+ metric_index.nil? ? nil : line_array[metric_index - 1]
27
+ end
28
+
24
29
  def parse_function(line)
25
- fn = line.split(' ')
26
- return if fn.include?('PASS') or fn.include?('ok')
27
- {
28
- name: fn.first,
29
- iterations: fn[1],
30
- ns_op: fn[2],
31
- bytes_op: fn[4],
32
- allocs_op: fn[6]
33
- }
30
+
31
+ line_array = line.split(' ')
32
+ parsed = {}
33
+ parsed[:name] = line_array.first
34
+ parsed[:iterations] = line_array[1]
35
+ parsed[:ns_op] = get_metric(line_array, 'ns/op')
36
+ parsed[:allocs_op] = get_metric(line_array, 'allocs/op')
37
+ parsed[:mb_s] = get_metric(line_array, 'MB/s')
38
+ parsed[:bytes_op] = get_metric(line_array, 'B/op')
39
+ parsed
34
40
  end
35
41
 
36
42
  class << self
43
+
37
44
  def parse(raw_data)
38
45
  raise Bp::ParserError.new if raw_data.nil?
39
46
  Bp::Parsers::Go.new(raw_data)
@@ -1,11 +1,12 @@
1
1
  module Benchparser
2
2
 
3
3
  class Result
4
- attr_accessor :language, :functions
4
+ attr_accessor :language, :functions, :configs
5
5
 
6
6
  def initialize(language:)
7
7
  @language = language
8
8
  @functions = []
9
+ @configs = {}
9
10
  end
10
11
  end
11
12
  end
@@ -1,3 +1,3 @@
1
1
  module Benchparser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derich Pacheco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-19 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,5 +102,5 @@ rubyforge_project:
102
102
  rubygems_version: 2.6.14
103
103
  signing_key:
104
104
  specification_version: 4
105
- summary: Benchparser - benchmark output parser
105
+ summary: Benchparser - benchmark output parser for multiple languages
106
106
  test_files: []