Sha256: c22ce1de045a27f16efe1dda479e44e1bfd9201e60bae62796f1c293f88e6427

Contents?: true

Size: 781 Bytes

Versions: 10

Compression:

Stored size: 781 Bytes

Contents

require 'benchmark/ips'
require 'tty-reader'

input = StringIO.new("a")
output = StringIO.new
$stdin = input
reader = TTY::Reader.new(input, output)

Benchmark.ips do |x|
  x.report('getc') do
    input.rewind
    $stdin.getc
  end

  x.report('read_char') do
    input.rewind
    reader.read_char
  end

  x.compare!
end

# v0.1.0
#
# Calculating -------------------------------------
#                 getc     52462 i/100ms
#            read_char       751 i/100ms
# -------------------------------------------------
#                 getc  2484819.4 (±4.1%) i/s -   12433494 in   5.013438s
#            read_char     7736.4 (±2.9%) i/s -      39052 in   5.052628s
#
# Comparison:
#                 getc:  2484819.4 i/s
#            read_char:     7736.4 i/s - 321.19x slower

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/benchmarks/speed_read_char.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/benchmarks/speed_read_char.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/benchmarks/speed_read_char.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/benchmarks/speed_read_char.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/benchmarks/speed_read_char.rb
tty-reader-0.7.0 benchmarks/speed_read_char.rb
tty-reader-0.6.0 benchmarks/speed_read_char.rb
tty-reader-0.5.0 benchmarks/speed_read_char.rb
tty-reader-0.3.0 benchmarks/speed_read_char.rb
tty-reader-0.2.0 benchmarks/speed_read_char.rb