Sha256: 465ddb6a19a854b2f462d848dd54e617c10eee338f7e38faa0ae55e7e29c976a

Contents?: true

Size: 1.81 KB

Versions: 12

Compression:

Stored size: 1.81 KB

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

require File.expand_path('../test_helper', __FILE__)

# tests for bugs reported by users
class YarvTest < TestCase
  def setup
    super
    define_methods
  end

  def test_array_push_unoptimized
    a = nil
    result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
      a = self.array_push_unoptimized
    end
    assert_equal 2, a.length
    assert_equal ["YarvTest#test_array_push_unoptimized", "YarvTest#array_push_unoptimized", 'Array#<<', "Array#push"], result.threads.first.methods.map(&:full_name)
  end

  def test_array_push_optimized
    a = nil
    result = RubyProf::Profile.profile(measure_mode: RubyProf::WALL_TIME) do
      a = self.array_push_optimized
    end
    assert_equal(2, a.length)
    if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1')
      assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#push"], result.threads.first.methods.map(&:full_name))
    else
      assert_equal(["YarvTest#test_array_push_optimized", "YarvTest#array_push_optimized", "Array#<<", "Array#push"], result.threads.first.methods.map(&:full_name))
    end
  end

  private

  def define_methods
    return if respond_to?(:array_push_optimized)
    old_compile_option = RubyVM::InstructionSequence.compile_option
    RubyVM::InstructionSequence.compile_option = {
      :trace_instruction => true,
      :specialized_instruction => false
    }
    self.class.class_eval <<-"EOM"
      def array_push_unoptimized
        a = []
        a << 1
        a.push 2
      end
    EOM
    RubyVM::InstructionSequence.compile_option = old_compile_option
    self.class.class_eval <<-"EOM"
      def array_push_optimized
        a = []
        a << 1
        a.push 2
      end
    EOM
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
ruby-prof-1.7.1-x64-mingw-ucrt test/yarv_test.rb
ruby-prof-1.7.1 test/yarv_test.rb
ruby-prof-1.7.0-x64-mingw-ucrt test/yarv_test.rb
ruby-prof-1.7.0 test/yarv_test.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/test/yarv_test.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/ruby-prof-1.6.3/test/yarv_test.rb
ruby-prof-1.6.3-x64-mingw-ucrt test/yarv_test.rb
ruby-prof-1.6.3 test/yarv_test.rb
ruby-prof-1.6.2-x64-mingw-ucrt test/yarv_test.rb
ruby-prof-1.6.2 test/yarv_test.rb
ruby-prof-1.6.1 test/yarv_test.rb
ruby-prof-1.6.1-x64-mingw-ucrt test/yarv_test.rb