File: threadsave.rb

package info (click to toggle)
ruby-fast-gettext 4.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 676 kB
  • sloc: ruby: 3,209; makefile: 4
file content (23 lines) | stat: -rw-r--r-- 729 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

require 'benchmark'
BASELINE = 0
def test
  result = Benchmark.measure { 1_000_000.times { yield } }
  result.to_s.strip.split(' ').first.to_f - BASELINE
end

BASELINE = (test {})
Thread.current[:library_name] = {}
other = "x"
puts "Ruby #{VERSION}"

puts "generic:"
puts "  Symbol: #{test { Thread.current[:library_name][:just_a_symbol] }}s"
puts "  String concat: #{test { Thread.current['xxxxxx' << other.to_s] }}s"
puts "  String add: #{test { Thread.current['xxxxxx' + other.to_s] }}s"
puts "  String insert: #{test { Thread.current["xxxxxx#{other}"] }}s"

puts "single:"
puts "  Symbol: #{test { Thread.current[:long_unique_symbol] }}s"
puts "  String: #{test { Thread.current['xxxxxx'] }}s"