ruby-changes:72985
From: Takashi <ko1@a...>
Date: Sat, 20 Aug 2022 06:45:27 +0900 (JST)
Subject: [ruby-changes:72985] fc4acf8cae (master): Make benchmark indentation consistent
https://git.ruby-lang.org/ruby.git/commit/?id=fc4acf8cae From fc4acf8cae82e5196186d3278d831f2438479d91 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun <takashikkbn@g...> Date: Fri, 19 Aug 2022 14:42:50 -0700 Subject: Make benchmark indentation consistent Related to https://github.com/Shopify/yjit-bench/pull/109 --- benchmark/so_nbody.rb | 58 +++++++++++++++++------------------ benchmark/vm_ivar_set_on_instance.yml | 52 +++++++++++++++---------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/benchmark/so_nbody.rb b/benchmark/so_nbody.rb index d6c5bb9e61..9884fc4edc 100644 --- a/benchmark/so_nbody.rb +++ b/benchmark/so_nbody.rb @@ -12,38 +12,38 @@ def _puts *args https://github.com/ruby/ruby/blob/trunk/benchmark/so_nbody.rb#L12 end class Planet - attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass + attr_accessor :x, :y, :z, :vx, :vy, :vz, :mass - def initialize(x, y, z, vx, vy, vz, mass) - @x, @y, @z = x, y, z - @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR - @mass = mass * SOLAR_MASS - end - - def move_from_i(bodies, nbodies, dt, i) - while i < nbodies - b2 = bodies[i] - dx = @x - b2.x - dy = @y - b2.y - dz = @z - b2.z - - distance = Math.sqrt(dx * dx + dy * dy + dz * dz) - mag = dt / (distance * distance * distance) - b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag - - @vx -= dx * b2_mass_mag - @vy -= dy * b2_mass_mag - @vz -= dz * b2_mass_mag - b2.vx += dx * b_mass_mag - b2.vy += dy * b_mass_mag - b2.vz += dz * b_mass_mag - i += 1 + def initialize(x, y, z, vx, vy, vz, mass) + @x, @y, @z = x, y, z + @vx, @vy, @vz = vx * DAYS_PER_YEAR, vy * DAYS_PER_YEAR, vz * DAYS_PER_YEAR + @mass = mass * SOLAR_MASS end - @x += dt * @vx - @y += dt * @vy - @z += dt * @vz - end + def move_from_i(bodies, nbodies, dt, i) + while i < nbodies + b2 = bodies[i] + dx = @x - b2.x + dy = @y - b2.y + dz = @z - b2.z + + distance = Math.sqrt(dx * dx + dy * dy + dz * dz) + mag = dt / (distance * distance * distance) + b_mass_mag, b2_mass_mag = @mass * mag, b2.mass * mag + + @vx -= dx * b2_mass_mag + @vy -= dy * b2_mass_mag + @vz -= dz * b2_mass_mag + b2.vx += dx * b_mass_mag + b2.vy += dy * b_mass_mag + b2.vz += dz * b_mass_mag + i += 1 + end + + @x += dt * @vx + @y += dt * @vy + @z += dt * @vz + end end def energy(bodies) diff --git a/benchmark/vm_ivar_set_on_instance.yml b/benchmark/vm_ivar_set_on_instance.yml index f0d5c16964..91857b7742 100644 --- a/benchmark/vm_ivar_set_on_instance.yml +++ b/benchmark/vm_ivar_set_on_instance.yml @@ -1,33 +1,33 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/vm_ivar_set_on_instance.yml#L1 prelude: | - class TheClass - def initialize - @v0 = 1 - @v1 = 2 - @v3 = 3 - @levar = 1 - end + class TheClass + def initialize + @v0 = 1 + @v1 = 2 + @v3 = 3 + @levar = 1 + end - def set_value_loop - # 1M - i = 0 - while i < 1000000 - # 10 times to de-emphasize loop overhead - @levar = i - @levar = i - @levar = i - @levar = i - @levar = i - @levar = i - @levar = i - @levar = i - @levar = i - @levar = i - i += 1 - end - end + def set_value_loop + # 1M + i = 0 + while i < 1000000 + # 10 times to de-emphasize loop overhead + @levar = i + @levar = i + @levar = i + @levar = i + @levar = i + @levar = i + @levar = i + @levar = i + @levar = i + @levar = i + i += 1 + end end + end - obj = TheClass.new + obj = TheClass.new benchmark: vm_ivar_set_on_instance: | -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/