Skip to content

Instantly share code, notes, and snippets.

@meh
Created February 7, 2014 10:58
Show Gist options
  • Select an option

  • Save meh/8860705 to your computer and use it in GitHub Desktop.

Select an option

Save meh/8860705 to your computer and use it in GitHub Desktop.
start = Time.now
# 0.000
=begin
%x{
var a = 0;
var b = 10000;
var x = [0, 1, 2, 3];
while (a < b) {
if (x[a % 4] != a % 4) {
#{fail};
}
a += 1;
}
}
=end
# 0.041
=begin
a = 0
b = 10_000
x = [0, 1, 2, 3]
%x{
while (a < b) {
if (#{x[`a % 4`]} != a % 4) {
#{fail};
}
a += 1;
}
}
=end
# 0.041
=begin
class Foo < Array; end
a = 0
b = 10_000
x = Foo[0, 1, 2, 3]
%x{
while (a < b) {
if (#{x[`a % 4`]} != a % 4) {
#{fail};
}
a += 1;
}
}
=end
# 0.190
# 0.000 (MRI)
=begin
a = 0
b = 10_000
x = [0, 1, 2, 3]
while a < b
unless x[a % 4] == a % 4
fail
end
a += 1
end
=end
# 0.210
# 0.001 (MRI)
=begin
class Foo < Array; end
a = 0
b = 10_000
x = Foo[0, 1, 2, 3]
while a < b
unless x[a % 4] == a % 4
fail
end
a += 1
end
=end
stop = Time.now
puts stop - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment