Skip to content

Commit

Permalink
updated benchmarks, removed differ benchmarks as it no longer compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
hamaluik committed Feb 15, 2020
1 parent dd38b37 commit 5337ec7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
bin/

# Created by https://www.gitignore.io/api/osx,linux,windows,visualstudiocode

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ class Headbutt {

## Benchmarks

| Test | Intersect | Headbutt (μs/iter) | Differ (μs/iter) |
|:-----|:---------:|---------:|-------:|
| line/line || 17.6 ± 0.4 | 1.1 ± 0 |
| line/line || 11.2 ± 0.5 | 0.9 ± 0 |
| circ/circ || 21.7 ± 0.2 | 3 ± 0 |
| circ/circ || 4.8 ± 0.1 | 1.6 ± 0 |
| pent/pent || 41.3 ± 0.4 | 31.5 ± 0.3 |
| pent/pent || 11.6 ± 0.1 | 7.4 ± 0 |
| Test | Intersect | Cpp (μs/iter) | Hashlink (μs/iter) | Node/Javascript (μs/iter) | Python (μs/iter) | Interp (μs/iter) |
|:-----|:---------:|---------:|-------:|-------:|-------:|-------:|
| line/line ||0.5 ± 0.1 | 4.4 ± 0.1 | 0.3 ± 1.1 | 18.6 ± 0.1 | 10.8 ± 0.1 |
| line/line || 0.3 ± 0 | 2.5 ± 0.1 | 0.2 ± 0.6 | 12 ± 0.1 | 6.8 ± 0 |
| circ/circ || 0.5 ± 0.1 | 5.5 ± 0.1 | 0.3 ± 0.9 | 23.8 ± 0.1 | 12.8 ± 0.1 |
| circ/circ || 0.2 ± 0 | 0.9 ± 0 | 0.1 ± 0.3 | 4.5 ± 0.1 | 2.6 ± 0 |
| pent/pent || 0.6 ± 0.1 | 7.5 ± 0.1 | 0.4 ± 1.1 | 55.4 ± 0.2 | 24.5 ± 0.1 |
| pent/pent || 0.2 ± 0 | 1.9 ± 0 | 0.1 ± 0.3 | 15.1 ± 0.3 | 6.7 ± 0 |
20 changes: 20 additions & 0 deletions bench.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-lib glm
-lib differ
-cp bench
-cp src
-main Main

--each
--js bin/bench.js

--next
--hl bin/bench.hl

--next
--python bin/bench.py

--next
--cpp bin/bench

--next
--interp
6 changes: 0 additions & 6 deletions bench.interp.hxml

This file was deleted.

62 changes: 19 additions & 43 deletions bench/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import headbutt.twod.Headbutt;
import haxe.ds.Vector;
import haxe.Timer;
import glm.Vec2;
import differ.Collision;

class Benchmark {
var results: Vector<Float>;
Expand Down Expand Up @@ -57,92 +56,69 @@ class Benchmark {
}

class Main {
static function println(s: String): Void {
#if sys
Sys.println(s);
#elseif js
js.html.Console.log(s);
#else
trace(s);
#end
}

public static function main(): Void {
var hb: Headbutt = new Headbutt();
Sys.println('| Test | Intersect | Headbutt (μs/iter) | Differ (μs/iter) |');
Sys.println('|:-----|:---------:|---------:|-------:|');
var hb = new Headbutt();
println('| Test | Intersect | Headbutt (μs/iter) |');
println('|:-----|:---------:|---------:|-------:|');

var lineA = new headbutt.twod.shapes.Line(new Vec2(-1, -1), new Vec2(1, 1));
var lineB = new headbutt.twod.shapes.Line(new Vec2(-1, 1), new Vec2(1, -1));
var lineC = new headbutt.twod.shapes.Line(new Vec2(1, -1), new Vec2(2, 1));
var rayA = new differ.shapes.Ray(new differ.math.Vector(-1, -1), new differ.math.Vector(1, 1));
var rayB = new differ.shapes.Ray(new differ.math.Vector(-1, 1), new differ.math.Vector(1, -1));
var rayC = new differ.shapes.Ray(new differ.math.Vector(1, -1), new differ.math.Vector(2, 1));

var line_line_int_hb = new Benchmark();
line_line_int_hb.run(function() {
hb.test(lineA, lineB);
});
var line_line_int_diff = new Benchmark();
line_line_int_diff.run(function() {
Collision.rayWithRay(rayA, rayB);
});
Sys.println('| line/line | ✔ | ${line_line_int_hb.toString()} | ${line_line_int_diff.toString()} |');
println('| line/line | ✔ | ${line_line_int_hb.toString()} |');

var line_line_noint_hb = new Benchmark();
line_line_noint_hb.run(function() {
hb.test(lineA, lineC);
});
var line_line_noint_diff = new Benchmark();
line_line_noint_diff.run(function() {
Collision.rayWithRay(rayA, rayC);
});
Sys.println('| line/line | ✗ | ${line_line_noint_hb.toString()} | ${line_line_noint_diff.toString()} |');
println('| line/line | ✗ | ${line_line_noint_hb.toString()} |');

var circleA = new headbutt.twod.shapes.Circle(new Vec2(0, 0), 0.5);
var circleB = new headbutt.twod.shapes.Circle(new Vec2(0.5, 0), 0.5);
var circleC = new headbutt.twod.shapes.Circle(new Vec2(3, 0), 0.5);
var dCircleA = new differ.shapes.Circle(0, 0, 0.5);
var dCircleB = new differ.shapes.Circle(0.5, 0, 0.5);
var dCircleC = new differ.shapes.Circle(3, 0, 0.5);

var circ_circ_int_hb = new Benchmark();
circ_circ_int_hb.run(function() {
hb.test(circleA, circleB);
});
var circ_circ_int_diff = new Benchmark();
circ_circ_int_diff.run(function() {
Collision.shapeWithShape(dCircleA, dCircleB);
});
Sys.println('| circ/circ | ✔ | ${circ_circ_int_hb.toString()} | ${circ_circ_int_diff.toString()} |');
println('| circ/circ | ✔ | ${circ_circ_int_hb.toString()} |');

var circ_circ_noint_hb = new Benchmark();
circ_circ_noint_hb.run(function() {
hb.test(circleA, circleC);
});
var circ_circ_noint_diff = new Benchmark();
circ_circ_noint_diff.run(function() {
Collision.shapeWithShape(dCircleA, dCircleC);
});
Sys.println('| circ/circ | ✗ | ${circ_circ_noint_hb.toString()} | ${circ_circ_noint_diff.toString()} |');
println('| circ/circ | ✗ | ${circ_circ_noint_hb.toString()} |');

var pentA = new headbutt.twod.shapes.Polygon([new Vec2(0, 1), new Vec2(1, 0.5), new Vec2(1, -1), new Vec2(-1, -1), new Vec2(-1, 0.5)]);
var pentB = new headbutt.twod.shapes.Polygon([new Vec2(0, 1), new Vec2(1, 0.5), new Vec2(1, -1), new Vec2(-1, -1), new Vec2(-1, 0.5)]);
pentB.set_trs(new Vec2(0.5, 0), 0, new Vec2(1, 1));
var pentC = new headbutt.twod.shapes.Polygon([new Vec2(0, 1), new Vec2(1, 0.5), new Vec2(1, -1), new Vec2(-1, -1), new Vec2(-1, 0.5)]);
pentC.set_trs(new Vec2(5, 0), 0, new Vec2(1, 1));
var dpentA = new differ.shapes.Polygon(0, 0, [new differ.math.Vector(0, 1), new differ.math.Vector(1, 0.5), new differ.math.Vector(1, -1), new differ.math.Vector(-1, -1), new differ.math.Vector(-1, 0.5)]);
var dpentB = new differ.shapes.Polygon(0.5, 0, [new differ.math.Vector(0, 1), new differ.math.Vector(1, 0.5), new differ.math.Vector(1, -1), new differ.math.Vector(-1, -1), new differ.math.Vector(-1, 0.5)]);
var dpentC = new differ.shapes.Polygon(5, 0, [new differ.math.Vector(0, 1), new differ.math.Vector(1, 0.5), new differ.math.Vector(1, -1), new differ.math.Vector(-1, -1), new differ.math.Vector(-1, 0.5)]);

var pent_pent_int_hb = new Benchmark();
pent_pent_int_hb.run(function() {
hb.test(pentA, pentB);
});
var pent_pent_int_diff = new Benchmark();
pent_pent_int_diff.run(function() {
Collision.shapeWithShape(dpentA, dpentB);
});
Sys.println('| pent/pent | ✔ | ${pent_pent_int_hb.toString()} | ${pent_pent_int_diff.toString()} |');
println('| pent/pent | ✔ | ${pent_pent_int_hb.toString()} |');

var pent_pent_noint_hb = new Benchmark();
pent_pent_noint_hb.run(function() {
hb.test(pentA, pentC);
});
var pent_pent_noint_diff = new Benchmark();
pent_pent_noint_diff.run(function() {
Collision.shapeWithShape(dpentA, dpentC);
});
Sys.println('| pent/pent | ✗ | ${pent_pent_noint_hb.toString()} | ${pent_pent_noint_diff.toString()} |');
println('| pent/pent | ✗ | ${pent_pent_noint_hb.toString()} |');
}
}

0 comments on commit 5337ec7

Please sign in to comment.