none
Time Samp Test RRS feed

  • Question

  • Celeron 2.0 Ghz CPU (Intel NUC)

    Windows Embedded Compact 7

    Running the test:

    for ( int i = 0; i < ITERATIONS; i++ ) // ITERATIONS = 1000
    {
        QueryPerformanceCounter(&li);
        time[i] = double(li.QuadPart) / PCFreq; //1,193,182 per second
    }

    Average of 11.990884 microseconds between each time stamp (a thousand time stamp calls).

    This seems extremely slow.

    Any ideas what may be causing the slow down?

    Thank You.

    Monday, November 11, 2013 3:09 AM

Answers

  • Thread priority?

    So you boiled it all down to one number, but what are the high values?  Low values?

    The low values will tell you what it is capable of doing.   The high values will tell you if your thread is blocked by interrupts or other threads.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    • Marked as answer by WindowsG Monday, November 25, 2013 3:49 AM
    Monday, November 11, 2013 3:02 PM
    Moderator

All replies

  • Thread priority?

    So you boiled it all down to one number, but what are the high values?  Low values?

    The low values will tell you what it is capable of doing.   The high values will tell you if your thread is blocked by interrupts or other threads.


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    • Marked as answer by WindowsG Monday, November 25, 2013 3:49 AM
    Monday, November 11, 2013 3:02 PM
    Moderator
  • Hi Bruce,

    Thanks for the reply.

    There is 1 thread (main)and I also used: CeSetThreadPriority(GetCurrentThread(), 1 ); // 0 - 255

    There were a few low values of 9 microseconds but most were around 11 (and a few at 15).

    Nevertheless,  I am confused - I was expecting 1 microsecond for this test....?

    (and  11 microseconds for something like a context switch.)

    Am I missing something here?

    Thank You.

    http://www.cs.columbia.edu/~%20sedwards/classes/2001/w4995-02/reports/ip.pdf


    #include <stdio.h>
    #include <windows.h> 
    #include <math.h>
    
    
    
    #define ITERATIONS 1000
    
    double PCFreq = 0.0;
    double CounterStart = 0.0;
    
    
    
    
    void getFrequency()
    {
    	LARGE_INTEGER li;
    	if ( !QueryPerformanceFrequency(&li) )
    	{
    		printf("QueryPerformaceFrequency FAILED!\n");
    	}
    
    	PCFreq = double(li.QuadPart) / 1000000.0; //micro-seconds
    }
    
    
    void timeStampTest()
    {
    	LARGE_INTEGER li;	
    	double time[ITERATIONS] = {0};
    	double difference[ITERATIONS - 1] = {0};
    	double sqdiff[ITERATIONS - 1] = {0};
            double average = 0.0;
    	double standardDeviation = 0.0;
    	double variance = 0.0;
    
    
    	// Main loop for tmer test
    	for ( int i = 0; i < ITERATIONS; i++ )
    	{
    		QueryPerformanceCounter(&li);
    		time[i] = double(li.QuadPart) / PCFreq;
    	}
    
    	// ** CALCULATIONS **
    
    	//calculate the difference between each call 
    	// and save in difference[]
    	for ( int j = 0; j < (ITERATIONS - 1)  ; j++ )
    	{
    		difference[j] = time[j+1] - time[j];
    	}
    
    	// average time between each timestamp call
    	for ( int k = 0; k < (ITERATIONS - 1)  ; k++ )
    	{
    	   average += difference[k];
    	}
    	// divide by number of differences calculated
    	average = average / (ITERATIONS - 1);
    
    
    
    	// Standard Deviation:
    	// For each number, subtract the average and square the result
    	for ( int m = 0; m < (ITERATIONS - 1)  ; m++ )
    	{
    		sqdiff[m] = pow( (difference[m] - average), 2);
    	}
    	// average of squared differences is the varaince
    	for ( int n = 0; n < (ITERATIONS - 1)  ; n++ )
    	{
    	   variance += sqdiff[n];
    	}
    	variance = variance / (ITERATIONS - 1);
    
    	// square root of variance is the Standard Deviation
    	standardDeviation = sqrt(variance);
    
    
    
    	printf("Average Time Between Time Stamp Calls: %f\n", average);
    	printf("Standard Deviation Between Time Stamp Calls: %f\n", standardDeviation);
    
    
    }
    
    int main()
    {
    
    	// main thread, high priority level 
    	if ( !CeSetThreadPriority(GetCurrentThread(), 1) )
    	{
    		printf("CeSetThreadPriority FAILED!\n");
    	}
    		
    
    	// set variable with frequency of high performance counter
    	getFrequency();
    
            //
    	timeStampTest();
    
    
    	return 0;
    }





    • Edited by WindowsG Monday, November 11, 2013 8:35 PM
    Monday, November 11, 2013 5:40 PM
  • It is late for me, but your calculations don't make sense to me.  QueryPerformanceFrequency() returns a value that indicates some value that equals a millisecond.  So dividing by 1000.0 would give you a value that equals a microsecond.  By making PCFreq smaller, by dividing by 100000.0, you increase the number of microseconds.  Also, by using that value the way you do causes a rounding error that might be fairly large, but not so important.

    As a sanity check, I would time the entire test loop in milliseconds. Don the numbers still make sense?


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    Tuesday, November 12, 2013 3:55 AM
    Moderator
  • Hi Bruce,

    As far as I can see it returns: X counts / 1 second

    "...the current performance-counter frequency, in counts per second."

    It is currently returning 1,193,182


    http://msdn.microsoft.com/en-us/library/windows/desktop/ms644905%28v=vs.85%29.aspx
    • Edited by WindowsG Wednesday, November 13, 2013 12:13 AM
    Wednesday, November 13, 2013 12:13 AM
  • You are correct, that is what I get for answering questions late in the evening...

    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com

    Wednesday, November 13, 2013 1:49 PM
    Moderator
  • Not a problem, I appreciate your time.

    Wednesday, November 13, 2013 6:08 PM