Sha256: 839d9fbc158396747b6682cc1b526e8433dd63bee258e90e32b3be591e45a7d4

Contents?: true

Size: 1.71 KB

Versions: 13

Compression:

Stored size: 1.71 KB

Contents

klasses = [
  Array,
  Class,
  # Complex,
  # Dir,
  Enumerable,
  Enumerator,
  Exception,
  Hash,
  # Kernel,
  Math,
  Method,
  Module,
  Object,
  Proc,
  Range,
  Rational,
  Regexp,
  Struct,
  String,
  Time
]

%x{
  function getOptimizationStatus(fn) {
    var optstatus = %GetOptimizationStatus(fn);

    return (optstatus & (1 << 6)) ? "[INTERPRETED]" : "[COMPILED]";
  }

  function triggerOptAndGetStatus(fn) {
    // using try/catch to avoid having to call functions properly
    try {
      // Fill type-info
      fn();
      // 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic
      fn();
    }
    catch (e) {}
    %OptimizeFunctionOnNextCall(fn);
    try {
      fn();
    }
    catch (e) {}
    return getOptimizationStatus(fn);
  }
}

optimization_status = Hash[klasses.map do |klass|
  methods = klass.instance_methods
  methods -= Object.instance_methods unless klass == Object
  methods -= [:product, :exit, :exit!, :at_exit]
  opt_status = Hash[methods.map do |method|
    method_func = `#{klass.instance_method(method)}.method`
    method_func = `#{method_func}.$$proxy_target || #{method_func}`
    [method, `triggerOptAndGetStatus(#{method_func})`]
  end]
  by_status_grouped = opt_status.group_by {|method, status| status }
  as_hash = Hash[by_status_grouped.map do |status, stuff|
    list = stuff.map {|val| val[0]}
    [status, list]
  end]
  [klass, as_hash]
end]

puts '----Report----'
optimization_status.sort_by {|klass,_| klass.name}.each do |klass, statuses|
  puts "---------------"
  puts "Class #{klass}:"
  puts "---------------"
  statuses.sort_by {|stat,_| stat }.each do |status, methods|
    methods.sort.each do |m|
      puts "  #{status} #{m}"
    end
  end
end

puts 'done!'

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
opal-1.7.4 tasks/performance/optimization_status.rb
opal-1.7.3 tasks/performance/optimization_status.rb
opal-1.7.2 tasks/performance/optimization_status.rb
opal-1.7.1 tasks/performance/optimization_status.rb
opal-1.7.0 tasks/performance/optimization_status.rb
opal-1.7.0.rc1 tasks/performance/optimization_status.rb
opal-1.6.1 tasks/performance/optimization_status.rb
opal-1.6.0 tasks/performance/optimization_status.rb
opal-1.6.0.rc1 tasks/performance/optimization_status.rb
opal-1.6.0.alpha1 tasks/performance/optimization_status.rb
opal-1.5.1 tasks/performance/optimization_status.rb
opal-1.5.0 tasks/performance/optimization_status.rb
opal-1.5.0.rc1 tasks/performance/optimization_status.rb