This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TSCL测函数时间,相同的代码两次调用为什么测出不同的时间?



同一个函数调用10w次, 发现测量得到的cycles不一样

代码如下:

     
         int  i;
         float test_c;
         test_c=0;
		 
         Vps_printf(" 11111111111111111111111111 \n");
         TSCL = 0;
         unsigned int t1=TSCL;
         //第一次调用
         for(i=0;i<100000;i++)
                   {
                            test_c=SqrtByCarmack3(i+test_c);
                   }
         unsigned int t2=TSCL;
         
         Vps_printf("test_a = %d ,%f\n",t2-t1,test_c);     

         Vps_printf(" 22222222222222222222222 \n");
         TSCL = 0;
          t1=TSCL;
         //第二次调用
         for(i=0;i<100000;i++)
                   {
                            test_c=SqrtByCarmack3(i+test_c);
                   }
         t2=TSCL; 
         
         Vps_printf(" test_a = %d ,%f\n",t2-t1,test_c);  

 

打印结果如下:

[DSP1  ]     41.738882 s:  11111111111111111111111111
[DSP1  ]     41.757823 s: test_a = 9461173 ,316.726593
[DSP1  ]     41.757853 s:  22222222222222222222222
[DSP1  ]     41.771091 s:  test_a = 6602662 ,316.726593

也就是 第一个10w次调用用了 9461173 个cycles   第二个10w次调用用了6602662 个cycles

测了多次都是这样,请问这是怎么回事,多谢了!