Sha256: 0e249729407748484177b9d40cc59190396eb16970b846f86ba3059f97d553dd

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

# $ bundle exec ruby script/bench.rb

require_relative "../bench/runner"

class ScmdBenchLogger
  def initialize(file_path)
    @file = File.open(file_path, "w")
    @ios = [@file, $stdout]
    yield self
    @file.close
  end

  def method_missing(meth, *args, &block)
    @ios.each do |io|
      io.respond_to?(meth.to_s) ? io.send(meth.to_s, *args, &block) : super
    end
  end

  def respond_to_missing?(*args)
    @ios.first.respond_to?(args.first.to_s) ? true : super
  end
end

def run_cmd(logger, *args)
  GC.disable

  ScmdBenchRunner.run(logger, *args)
  logger.puts

  GC.enable
  GC.start
end

ScmdBenchLogger.new("bench/results.txt") do |logger|
  run_cmd(logger, Scmd.new("echo hi"), 1)
  run_cmd(logger, Scmd.new("echo hi"), 10)
  run_cmd(logger, Scmd.new("echo hi"), 100)
  run_cmd(logger, Scmd.new("echo hi"), 1000)

  run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 1)
  run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 10)
  run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 100)
  run_cmd(logger, Scmd.new("cat test/support/bigger-than-64k.txt"), 1000)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
scmd-3.0.5 script/bench.rb
scmd-3.0.4 script/bench.rb