Skip to content

Instantly share code, notes, and snippets.

@profelis
Created May 30, 2013 13:12
Show Gist options
  • Select an option

  • Save profelis/5677715 to your computer and use it in GitHub Desktop.

Select an option

Save profelis/5677715 to your computer and use it in GitHub Desktop.

Revisions

  1. profelis created this gist May 30, 2013.
    34 changes: 34 additions & 0 deletions Measure.hx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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];
    }

    }