如何做,得到执行一个方法的cpu时间

解决方案 »

  1.   

    public static void main(String[] args) {
    long m,n;
    System.out.println(m=System.currentTimeMillis());
    int a=0;
    for(int i = 1;i<10000000;i++){
    a=a+i;
    }
    System.out.println(n=System.currentTimeMillis());
    System.out.println(n-m);

    }
      

  2.   

    在方法执行之前和之后分别调用一次System.currentTimeMillis()不行吗?
    更精确的(比如精确到微秒)可能得用到JNI了吧。
      

  3.   


    这样就可以获取到大概的时间,整个程序运行所需要的时间,但是这个不精确,问题涉及到线程的休眠和阻塞问题和其它很多进程的调度问题。
    所以一般来说,cpu运行时间要比程序执行时间短很多。
      

  4.   

    谢谢 所以想求助cpu时间如何取得 谁能帮助我啊 
      

  5.   

    ativesource.cpp
    D:\tools\vc66\MSDev98\MyProjects\native\nativesource.cpp(11) : error C2065: 's_currentProcess' : undeclared identifier
    D:\tools\vc66\MSDev98\MyProjects\native\nativesource.cpp(11) : error C2440: '=' : cannot convert from 'void *' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\tools\vc66\MSDev98\MyProjects\native\nativesource.cpp(14) : error C2065: 's_numberOfProcessors' : undeclared identifier
    D:\tools\vc66\MSDev98\MyProjects\native\nativesource.cpp(30) : error C2065: 'fileTimeToInt64' : undeclared identifier
    Error executing cl.exe.
    家那个头以后错误减少了 
    但是还是有 不知道怎么调试 ,链接中的例子 我不太会弄 那个可以测试cpu时间吗 我想测试web系统性能。
      

  6.   

    不要系统时间
    想要测试cpu时间 测试web性能 有什么好办法吗
      

  7.   

    http://www.99inf.net/SoftwareDev/Java/54523.htm
    谁能把链接中的例子搞通啊