File: speed.rb

package info (click to toggle)
ruby-tty-prompt 0.23.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,452 kB
  • sloc: ruby: 8,847; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 716 bytes parent folder | download | duplicates (2)
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
# coding: utf-8

require 'benchmark/ips'
require 'stringio'
require_relative '../lib/tty-prompt'

input  = ::StringIO.new
output = ::StringIO.new
prompt  = TTY::Prompt.new(input: input, output: output)

Benchmark.ips do |r|

  r.report("Ruby #puts") do
    output.puts "What is your name?"
  end

  r.report("TTY::Prompt #ask") do
    prompt.ask("What is your name?")
  end
end

# Calculating -------------------------------------
#           Ruby #puts     34601 i/100ms
#     TTY::Prompt #ask        12 i/100ms
# -------------------------------------------------
#           Ruby #puts   758640.5 (±14.9%) i/s -    3736908 in   5.028562s
#     TTY::Prompt #ask       63.1 (±7.9%) i/s -        324 in   5.176857s