benchmark 0.2.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eafbbb0ec7f26fb0f60f21a677e4f749670e912c9ff1948fec84aa0b6f8a08bd
4
- data.tar.gz: 32098b08dfca91b193cd47d3a009287afc4dabb36a093e8398998e78dcbcf2b3
3
+ metadata.gz: 145433cc28066cac5af1cb90961edfde1bd7b54e2ac05357874fb2f4be169a19
4
+ data.tar.gz: 3732c4e2aaef0eaf7ef4d9513e2bb5116ef18ee7e74546345ccb88f1b3bbddc2
5
5
  SHA512:
6
- metadata.gz: 2abb831bd071d73f72efe77b45ed4eca4eb861c124bdf976e6fb498e2c44edb7fbed91b4b4063a7a27f1c8652e8c365d45792ffc843d08925f50a564742c6832
7
- data.tar.gz: 8b46138b50800e8ef91417763c238e0cb1ab55f863fa491d92c932a8aa13168065cf19f22de3ed79b5c580728647da3904b423c6de463d775d489d6960f032a0
6
+ metadata.gz: a11e3910a7c5a636d7993c80ba736682c41a407c3b5d18fe936096c383ffb7c8781a8fae4013760271c05a819c8f126cf17835e91d327c3cb7066e735aed3272
7
+ data.tar.gz: 3d003fd533f1b4291ac21cdb6b02b93ebbb19e6ca5f7a90dd677416321c49fa2713cc75ccd9a92a89ccdc62d0e0a3cf48f6c2c671ae8935854194fbecc9eafee
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -0,0 +1,46 @@
1
+ name: Publish gem to rubygems.org
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ push:
13
+ if: github.repository == 'ruby/benchmark'
14
+ runs-on: ubuntu-latest
15
+
16
+ environment:
17
+ name: rubygems.org
18
+ url: https://rubygems.org/gems/benchmark
19
+
20
+ permissions:
21
+ contents: write
22
+ id-token: write
23
+
24
+ steps:
25
+ - name: Harden Runner
26
+ uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
27
+ with:
28
+ egress-policy: audit
29
+
30
+ - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
31
+
32
+ - name: Set up Ruby
33
+ uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0
34
+ with:
35
+ bundler-cache: true
36
+ ruby-version: ruby
37
+
38
+ - name: Publish to RubyGems
39
+ uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1
40
+
41
+ - name: Create GitHub release
42
+ run: |
43
+ tag_name="$(git describe --tags --abbrev=0)"
44
+ gh release create "${tag_name}" --verify-tag --generate-notes
45
+ env:
46
+ GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }}
@@ -1,17 +1,27 @@
1
- name: build
1
+ name: test
2
2
 
3
3
  on: [push, pull_request]
4
4
 
5
5
  jobs:
6
- build:
6
+ ruby-versions:
7
+ uses: ruby/actions/.github/workflows/ruby_versions.yml@master
8
+ with:
9
+ min_version: 2.5
10
+
11
+ test:
12
+ needs: ruby-versions
7
13
  name: build (${{ matrix.ruby }} / ${{ matrix.os }})
8
14
  strategy:
9
15
  matrix:
10
- ruby: [ '3.0', 2.7, 2.6, 2.5, head ]
11
- os: [ ubuntu-latest, macos-latest ]
16
+ ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
17
+ os: [ ubuntu-latest, macos-latest, windows-latest ]
18
+ exclude:
19
+ - { os: macos-latest, ruby: 2.5 }
20
+ - { os: windows-latest, ruby: truffleruby-head }
21
+ - { os: windows-latest, ruby: truffleruby }
12
22
  runs-on: ${{ matrix.os }}
13
23
  steps:
14
- - uses: actions/checkout@v2
24
+ - uses: actions/checkout@v4
15
25
  - name: Set up Ruby
16
26
  uses: ruby/setup-ruby@v1
17
27
  with:
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
5
5
  are met:
6
6
  1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
7
+ notice, this list of conditions and the following disclaimer.
8
8
  2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
11
 
12
12
  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
13
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a. place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b. use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c. give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d. make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a. distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b. accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c. give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d. make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
data/benchmark.gemspec CHANGED
@@ -1,12 +1,13 @@
1
- begin
2
- require_relative "lib/benchmark/version"
3
- rescue LoadError # Fallback to load version file in ruby core repository
4
- require_relative "version"
1
+ name = File.basename(__FILE__, ".gemspec")
2
+ version = ["lib", Array.new(name.count("-")+1, ".").join("/")].find do |dir|
3
+ break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
4
+ /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
5
+ end rescue nil
5
6
  end
6
7
 
7
8
  Gem::Specification.new do |spec|
8
- spec.name = "benchmark"
9
- spec.version = Benchmark::VERSION
9
+ spec.name = name
10
+ spec.version = version
10
11
  spec.authors = ["Yukihiro Matsumoto"]
11
12
  spec.email = ["matz@ruby-lang.org"]
12
13
 
@@ -15,13 +16,15 @@ Gem::Specification.new do |spec|
15
16
  spec.homepage = "https://github.com/ruby/benchmark"
16
17
  spec.licenses = ["Ruby", "BSD-2-Clause"]
17
18
 
19
+ spec.required_ruby_version = ">= 2.1.0"
20
+
18
21
  spec.metadata["homepage_uri"] = spec.homepage
19
22
  spec.metadata["source_code_uri"] = spec.homepage
20
23
 
21
24
  # Specify which files should be added to the gem when it is released.
22
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
26
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
- `git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ `git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
28
  end
26
29
  spec.bindir = "exe"
27
30
  spec.executables = []
data/lib/benchmark.rb CHANGED
@@ -121,6 +121,8 @@
121
121
 
122
122
  module Benchmark
123
123
 
124
+ VERSION = "0.4.0"
125
+
124
126
  BENCHMARK_VERSION = "2002-04-25" # :nodoc:
125
127
 
126
128
  # Invokes the block with a Benchmark::Report object, which
@@ -171,9 +173,15 @@ module Benchmark
171
173
  label_width ||= 0
172
174
  label_width += 1
173
175
  format ||= FORMAT
174
- print ' '*label_width + caption unless caption.empty?
175
176
  report = Report.new(label_width, format)
176
177
  results = yield(report)
178
+
179
+ print " " * report.width + caption unless caption.empty?
180
+ report.list.each { |i|
181
+ print i.label.to_s.ljust(report.width)
182
+ print i.format(report.format, *format)
183
+ }
184
+
177
185
  Array === results and results.grep(Tms).each {|t|
178
186
  print((labels.shift || t.label || "").ljust(label_width), t.format(format))
179
187
  }
@@ -305,6 +313,10 @@ module Benchmark
305
313
 
306
314
  #
307
315
  # Returns the elapsed real time used to execute the given block.
316
+ # The unit of time is seconds.
317
+ #
318
+ # Benchmark.realtime { "a" * 1_000_000_000 }
319
+ # #=> 0.5098029999935534
308
320
  #
309
321
  def realtime # :yield:
310
322
  r0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -374,16 +386,16 @@ module Benchmark
374
386
  # formatting rules.
375
387
  #
376
388
  def item(label = "", *format, &blk) # :yield:
377
- print label.to_s.ljust(@width)
389
+ w = label.to_s.length
390
+ @width = w if @width < w
378
391
  @list << res = Benchmark.measure(label, &blk)
379
- print res.format(@format, *format)
380
392
  res
381
393
  end
382
394
 
383
395
  alias report item
384
396
 
385
397
  # An array of Benchmark::Tms objects representing each item.
386
- attr_reader :list
398
+ attr_reader :width, :format, :list
387
399
  end
388
400
 
389
401
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: benchmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-14 00:00:00.000000000 Z
11
+ date: 2024-11-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a performance benchmarking library
14
14
  email:
@@ -17,17 +17,19 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".github/dependabot.yml"
21
+ - ".github/workflows/push_gem.yml"
20
22
  - ".github/workflows/test.yml"
21
23
  - ".gitignore"
24
+ - BSDL
25
+ - COPYING
22
26
  - Gemfile
23
- - LICENSE.txt
24
27
  - README.md
25
28
  - Rakefile
26
29
  - benchmark.gemspec
27
30
  - bin/console
28
31
  - bin/setup
29
32
  - lib/benchmark.rb
30
- - lib/benchmark/version.rb
31
33
  homepage: https://github.com/ruby/benchmark
32
34
  licenses:
33
35
  - Ruby
@@ -35,7 +37,7 @@ licenses:
35
37
  metadata:
36
38
  homepage_uri: https://github.com/ruby/benchmark
37
39
  source_code_uri: https://github.com/ruby/benchmark
38
- post_install_message:
40
+ post_install_message:
39
41
  rdoc_options: []
40
42
  require_paths:
41
43
  - lib
@@ -43,15 +45,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
45
  requirements:
44
46
  - - ">="
45
47
  - !ruby/object:Gem::Version
46
- version: '0'
48
+ version: 2.1.0
47
49
  required_rubygems_version: !ruby/object:Gem::Requirement
48
50
  requirements:
49
51
  - - ">="
50
52
  - !ruby/object:Gem::Version
51
53
  version: '0'
52
54
  requirements: []
53
- rubygems_version: 3.3.0.dev
54
- signing_key:
55
+ rubygems_version: 3.5.11
56
+ signing_key:
55
57
  specification_version: 4
56
58
  summary: a performance benchmarking library
57
59
  test_files: []
@@ -1,3 +0,0 @@
1
- module Benchmark
2
- VERSION = "0.2.0"
3
- end