Sha256: e609aa5c8b7eb322f8e9290e9e6bae8ed6999df6041eb3ff282f3054352182a6

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

# frozen_string_literal: true
require 'benchmark'
require File.join(File.dirname(__FILE__), '..', 'lib', 'yard')

TIMES = (ARGV[0] || 10_000).to_i

def bench_builtins(name)
  YARD::CodeObjects::BUILTIN_EXCEPTIONS_HASH.key? name
end

def bench_eval(name)
  eval(name).is_a?(Class)
rescue
  false
end

Benchmark.bmbm do |b|
  b.report("builtins PASS") { TIMES.times { YARD::CodeObjects::BUILTIN_EXCEPTIONS.each {|y| bench_builtins(y) } } }
  b.report("eval PASS") { TIMES.times { YARD::CodeObjects::BUILTIN_EXCEPTIONS.each {|y| bench_eval(y) } } }
  b.report("builtins FAIL") { TIMES.times { YARD::CodeObjects::BUILTIN_MODULES.each {|y| bench_builtins(y) } } }
  b.report("eval FAIL") { TIMES.times { YARD::CodeObjects::BUILTIN_MODULES.each {|y| bench_eval(y) } } }
  b.report("builtins ANY") { TIMES.times { YARD::CodeObjects::BUILTIN_CLASSES.each {|y| bench_builtins(y) } } }
  b.report("eval ANY") { TIMES.times { YARD::CodeObjects::BUILTIN_CLASSES.each {|y| bench_eval(y) } } }
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yard-0.9.18 benchmarks/builtins_vs_eval.rb
yard-0.9.17 benchmarks/builtins_vs_eval.rb