Time expression

来自MudWiki

名称

   time_expression() - return the amount of real time that an expression took

语法

   int time_expression( mixed expr );

描述

   Evaluate <expr>. The amount of real time that passed during the evaluation of <expr>, in microseconds, is returned. The precision of the value is not necessarily 1 microsecond; in fact, it probably is much less precise.

   另外 time_expression 本质上并不是外部函数而是一个语言结构(类似还有sscanf, catch, parse_command等)。

示例

int main(object me, string arg)
{
    int cost;

    cost = time_expression
    {
        for (int i = 0; i < 100; i++)
        {
            printf("i = %d\n", i);
        }
    };

    printf("代码执行耗时:%d 微秒\n", cost);

    return 1;
}

参考

   rusage(3), function_profile(3), time(3), perf_counter_ns(3)