Sha256: b6f01dc380e8ae5fb6a84c16264d9ee0493a3a7b046b48755054fa268c86bc72

Contents?: true

Size: 1.97 KB

Versions: 4

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

# Play from the console with:
#   play scripts/benchmarking/object_inspector.rb

require "ostruct"
require "benchmark/ips"

inspector_klass = ObjectInspector::Inspector

OBJECT_WITH_FLAGS_AND_INFO_AND_NAME ||=
  OpenStruct.new(
    identification: "IDENTIFICATION",
    flags: "FLAG1 | FLAG2",
    info: "INFO",
    name: "NAME")
OBJECT_WITH_FLAGS_AND_INFO ||=
  OpenStruct.new(
    identification: "IDENTIFICATION",
    flags: "FLAG1 | FLAG2",
    info: "INFO")
OBJECT_WITH_FLAGS_AND_NAME ||=
  OpenStruct.new(
    identification: "IDENTIFICATION",
    flags: "FLAG1 | FLAG2",
    name: "NAME")
OBJECT_WITH_INFO_AND_NAME ||=
  OpenStruct.new(
    identification: "IDENTIFICATION",
    info: "INFO",
    name: "NAME")
OBJECT_WITH_NAME ||=
  OpenStruct.new(
    identification: "IDENTIFICATION",
    name: "NAME")
OBJECT_WITH_FLAGS ||=
  OpenStruct.new(
    identification: "IDENTIFICATION",
    flags: "FLAG1 | FLAG2")
OBJECT_WITH_INFO ||=
  OpenStruct.new(
    identification: "IDENTIFICATION",
    info: "INFO")
OBJECT_WITH_BASE ||=
  OpenStruct.new(
    identification: "IDENTIFICATION")

puts "== Averaged ============================================================="
Benchmark.ips { |x|
  x.report(inspector_klass) {
    inspector_klass.inspect(OBJECT_WITH_FLAGS_AND_INFO_AND_NAME)
    inspector_klass.inspect(OBJECT_WITH_FLAGS_AND_INFO)
    inspector_klass.inspect(OBJECT_WITH_FLAGS_AND_NAME)
    inspector_klass.inspect(OBJECT_WITH_INFO_AND_NAME)
    inspector_klass.inspect(OBJECT_WITH_NAME)
    inspector_klass.inspect(OBJECT_WITH_FLAGS)
    inspector_klass.inspect(OBJECT_WITH_INFO)
    inspector_klass.inspect(OBJECT_WITH_BASE)
  }

  x.report("Ruby") {
    OBJECT_WITH_FLAGS_AND_INFO_AND_NAME.inspect
    OBJECT_WITH_FLAGS_AND_INFO.inspect
    OBJECT_WITH_FLAGS_AND_NAME.inspect
    OBJECT_WITH_INFO_AND_NAME.inspect
    OBJECT_WITH_NAME.inspect
    OBJECT_WITH_FLAGS.inspect
    OBJECT_WITH_INFO.inspect
    OBJECT_WITH_BASE.inspect
  }

  x.compare!
}
puts "== Done"

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
object_inspector-0.6.2 scripts/benchmarking/object_inspector.rb
object_inspector-0.6.1 scripts/benchmarking/object_inspector.rb
object_inspector-0.6.0 scripts/benchmarking/object_inspector.rb
object_inspector-0.5.2 scripts/benchmarking/object_inspector.rb