File: bench.rb

package info (click to toggle)
rust-magnus 0.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,468 kB
  • sloc: ruby: 150; sh: 17; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 675 bytes parent folder | download
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
32
33
34
35
require "benchmark"
require_relative "../lib/rust_blank"

n = 1_000_000
Benchmark.bmbm do |x|
  x.report("empty") do
    n.times {"".blank?}
  end

  x.report("blank") do
    n.times {" ".blank?}
  end

  x.report("present") do
    n.times {"x".blank?}
  end

  x.report("lots of spaces blank") do
    n.times {"                                          ".blank?}
  end

  x.report("lots of spaces present") do
    n.times {"                                          x".blank?}
  end

  x.report("blank US-ASCII") do
    s = " ".encode("US-ASCII")
    n.times {s.blank?}
  end

  x.report("blank non-utf-8") do
    s = " ".encode("UTF-16LE")
    n.times {s.blank?}
  end
end