Skip to content

Instantly share code, notes, and snippets.

@profelis
Last active February 29, 2020 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save profelis/1a152882cb888b5e581f98a747105455 to your computer and use it in GitHub Desktop.
Save profelis/1a152882cb888b5e581f98a747105455 to your computer and use it in GitHub Desktop.
haxe + numba
-cp .
-D analyzer-optimize
-main Test
-python testhx.py
--dce full
import haxe.Timer;
import haxe.Constraints.Function;
@:pythonImport("numba.typed", "List")
extern class List extends Array<Dynamic> {
public function new();
public function append(val:Dynamic):Void;
public function __iter__():Dynamic;
}
@:pythonImport("numba")
extern class Numba {
static function njit(func:Function):Function;
}
class Test {
static function main() {
var arr = new List();
for (i in 0...1000000)
arr.append(i + 0.1);
var arr2 = new List();
for (i in 0...1000000)
arr2.append(i + 0.1);
var jit = Numba.njit(sum);
var start = Timer.stamp();
var a = jit(arr, arr2);
trace(a);
trace("first calc", Timer.stamp() - start);
var start = Timer.stamp();
var a = jit(arr, arr2);
trace(a);
trace("second calc", Timer.stamp() - start);
}
static function sum(arr:List, arr2:List) {
var res = 0.;
var len = arr.length;
var len2 = arr.length;
var i = -1;
var j = -1;
while (++i < len)
while (++j < len2)
res += (arr[i] : Float) + (arr2[j] : Float);
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment