File: output_stringio_vs_tempfile.rb

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (31 lines) | stat: -rw-r--r-- 986 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'rubygems'
require 'bundler/setup'
require 'benchmark'
require 'rspec/expectations'
include RSpec::Matchers

n = 100_000

Benchmark.bm(25) do |bm|
  bm.report("to_stdout with StringIO") do
    n.times { expect {}.not_to output('foo').to_stdout }
  end

  bm.report("to_stdout with Tempfile") do
    n.times { expect {}.not_to output('foo').to_stdout_from_any_process }
  end

  bm.report("to_stderr with StringIO") do
    n.times { expect {}.not_to output('foo').to_stderr }
  end

  bm.report("to_stderr with Tempfile") do
    n.times { expect {}.not_to output('foo').to_stderr_from_any_process }
  end
end

#                                 user     system      total        real
# to_stdout with StringIO     0.470000   0.010000   0.480000 (  0.467317)
# to_stdout with Tempfile     8.920000   7.420000  16.340000 ( 16.355174)
# to_stderr with StringIO     0.460000   0.000000   0.460000 (  0.454059)
# to_stderr with Tempfile     8.930000   7.560000  16.490000 ( 16.494696)