Created
May 21, 2025 23:10
-
-
Save KonnorRogers/b58e2818ff62dd999c4e905a8be6efd1 to your computer and use it in GitHub Desktop.
A dragonruby benchmark of array creation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tick args | |
if args.inputs.keyboard.key_down.r | |
$gtk.reset | |
end | |
# press i to run benchmark using iterations | |
if args.inputs.keyboard.key_down.b | |
max_particles = 10_000 | |
args.gtk.console.show | |
args.gtk.benchmark( | |
iterations: 100, # number of iterations | |
with_dup: lambda { | |
hash = { | |
active: false, | |
x: 0.0, y: 0.0, | |
vx: 0.0, vy: 0.0, | |
ax: 0.0, ay: 0.0, | |
life: 0, | |
ttl: 0, | |
size: 1, | |
path: 'sprites/pixel.png', | |
} | |
@particles = Array.new(max_particles) do | |
hash.dup | |
end | |
}, | |
with_clone: lambda { | |
hash = { | |
active: false, | |
x: 0.0, y: 0.0, | |
vx: 0.0, vy: 0.0, | |
ax: 0.0, ay: 0.0, | |
life: 0, | |
ttl: 0, | |
size: 1, | |
path: 'sprites/pixel.png', | |
} | |
@particles = Array.new(max_particles) do | |
hash.clone | |
end | |
}, | |
with_object_creation: lambda { | |
@particles = Array.new(max_particles) do | |
{ | |
active: false, | |
x: 0.0, y: 0.0, | |
vx: 0.0, vy: 0.0, | |
ax: 0.0, ay: 0.0, | |
life: 0, | |
ttl: 0, | |
size: 1, | |
path: 'sprites/pixel.png', | |
} | |
end | |
} | |
) | |
end | |
end | |
$gtk.reset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment