自动获取某段代码的浮点运算计数的方法 [英] Automatic way to obtain the floating-point operation count for some piece of code

查看:137
本文介绍了自动获取某段代码的浮点运算计数的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些相当复杂且高度模板化的代码(C ++,但这可能不是很相关),我想知道其中的add,subs,muls,div和sqrts的数量.有没有一种自动的方式来获取这些信息(编译器可以很容易地计算出来)?我试图自己在生成的汇编代码中对其进行计数,但对jpjmpcall s感到困惑.

I have some rather complex and highly templated code (C++, but this may not be very relevant) of which I'd like to know the number of adds, subs, muls, divs, and sqrts at execution. Is there an automatic way to get this information (the compiler could work it out easily)? I tried to count it myself in the assembler code generated, but got confused with jp, jmp, and calls.

推荐答案

对于某些类似浮点的类型,我建议覆盖+-*/运算符和sqrt函数,您可以在其中计算出它们的用途.

I would suggest to override +, -, *, / operators and sqrt function for some float-like type, in which you can count their use.

类似这样的东西:

struct Double {
    double val;
    Double(double v): val(v) {}
    static unsigned add_count = 0;
    Double operator+(Double other) {
        ++add_count;
        return Double(val + other.val);
    }
};

do_your_stuff<Double>();

这篇关于自动获取某段代码的浮点运算计数的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆