Sha256: da88cb04c6a775fb9864a248388b5425cacd03767b821d8053b23109ec8230ba

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

class BenchmarkCLI
  module Ruby
    class SelfClass
      include Helpers

      def call
        header 'Check if repeatative `self.class` impacts performance'

        Benchmark.ips do |benchmark|
          benchmark.config(stats: :bootstrap, confidence: 95)

          run_benchmarks(benchmark)

          benchmark.compare!
        end
      end

      private

      def run_benchmarks(benchmark)
        report_self_class(benchmark)
        report_klass(benchmark)
      end

      def report_self_class(benchmark)
        benchmark.report '[self.class, ... 10 times]' do
          self_class_10_times
        end
      end

      def self_class_10_times # rubocop:disable Metrics/MethodLength
        [
          self.class,
          self.class,
          self.class,
          self.class,
          self.class,
          self.class,
          self.class,
          self.class,
          self.class,
          self.class
        ]
      end

      def report_klass(benchmark)
        benchmark.report 'klass = self.class; [klass, ... 10 times]' do
          klass_10_times
        end
      end

      def klass_10_times # rubocop:disable Metrics/MethodLength
        klass = self.class
        [
          klass,
          klass,
          klass,
          klass,
          klass,
          klass,
          klass,
          klass,
          klass,
          klass
        ]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flows-0.6.0 bin/benchmark_cli/ruby/self_class.rb
flows-0.5.1 bin/benchmark_cli/ruby/self_class.rb
flows-0.5.0 bin/benchmark_cli/ruby/self_class.rb
flows-0.4.0 bin/benchmark_cli/ruby/self_class.rb