Created
May 30, 2013 13:12
-
-
Save profelis/5677715 to your computer and use it in GitHub Desktop.
Measure macros (Haxe 3)
This file contains 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
package ; | |
#if macro | |
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
#end | |
/** | |
* ... | |
* @author deep <[email protected]> | |
*/ | |
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]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
moved https://github.com/profelis/escape/blob/master/src/deep/tools/Measure.hx