Sha256: c35eda9f144657c969b0a3192bf5ff131eb734365b22e5bb07ad10056bfc0790

Contents?: true

Size: 986 Bytes

Versions: 13

Compression:

Stored size: 986 Bytes

Contents

#!/usr/bin/env ruby

require 'benchmark'

n = 10000000
line = 's tupBel1.scaffold_3803.1-85889    33686 61 +    85889 ttcaggaagggggcccaaaacgcttgagtggtcagctctta-ttttgcgtttactggatggg'

Benchmark.bmbm do |x|
  x.report("case with strings") do
    n.times do
      i = 0
      case line[0]
      when 's'
        i += 1
      when 'i', 'e', 'q', '#', nil
        next
      else
        raise "foo"
      end
    end
  end
  S = 's'.getbyte(0)
  I = 'i'.getbyte(0)
  E = 'e'.getbyte(0)
  Q = 'q'.getbyte(0)
  COMMENT = '#'.getbyte(0)
  x.report("case with bytes") do
    n.times do
      i = 0
      case line.getbyte(0)
      when S
        i += 1
      when I, E, Q, COMMENT, nil
        next
      else
        raise "foo"
      end
    end
  end
  x.report("if/else with bytes") do
    n.times do
      i = 0
      b = line.getbyte(0)
      if b == S
        i += 1
      elsif [I, E, Q, COMMENT, nil].contain?(b)
        next
      else
        raise "foo"
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bio-maf-1.0.1-java benchmarks/dispatch_bench
bio-maf-1.0.1 benchmarks/dispatch_bench
bio-maf-1.0.0-java benchmarks/dispatch_bench
bio-maf-1.0.0 benchmarks/dispatch_bench
bio-maf-0.3.2-java benchmarks/dispatch_bench
bio-maf-0.3.2 benchmarks/dispatch_bench
bio-maf-0.3.1 benchmarks/dispatch_bench
bio-maf-0.3.0-java benchmarks/dispatch_bench
bio-maf-0.3.0 benchmarks/dispatch_bench
bio-maf-0.2.0-java benchmarks/dispatch_bench
bio-maf-0.2.0 benchmarks/dispatch_bench
bio-maf-0.1.0 benchmarks/dispatch_bench
bio-maf-0.1.0-java benchmarks/dispatch_bench