Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@profelis
Created May 30, 2013 13:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save profelis/5677715 to your computer and use it in GitHub Desktop.
Save profelis/5677715 to your computer and use it in GitHub Desktop.
Measure macros (Haxe 3)
package ;
#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
#end
/**
* ...
* @author deep <system.grand@gmail.com>
*/
class Measure
{
/**
* Usage:
* Measure.run( "parse time ", b.parse(), c.parse() );
* or
* Measure.run( "parse time ", { b.parse(); c.parse() } );
*
* -D measure - on/off measure
*/
macro static public function run(msg:String, exprs:Array<Expr>) {
if (Context.defined("measure")) {
exprs.unshift(macro var ____t____ = haxe.Timer.stamp());
exprs.push(macro trace($v { msg } + (haxe.Timer.stamp() - ____t____)));
return {expr:EBlock(exprs), pos:Context.currentPos()}
}
return if (exprs.length > 1)
{expr:EBlock(exprs), pos:Context.currentPos()}
else
exprs[0];
}
}
@profelis
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment