Results 1 to 3 of 3

Thread: QueryPerformance

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60

    QueryPerformance

    Hello

    Can anybody explain to me why the following four red lines of code yield different results to their purple line counterparts? By my reckoning the results should be te same but one set are printed to the console window and the other to a text file. The purple lines are definitely creating correct results because they are a product of help code for Microsoft Visual Studio .NET and the results look good. The red lines of code (my code) are definitely producing incorrect results and all four of the outputs are often identical. Am I doing some memory management incorrectly???
    Code:
    #include "stdafx.h"
    
    #using <mscorlib.dll>
    #include <tchar.h>
    #include <windows.h>
    #include <stdio.h>
    
    using namespace System;
    
    // This is the entry point for this application
    int _tmain(void)
    {
        _int64 ctr1 = 0, ctr2 = 0, freq = 0;
    	int acc = 0, i = 0;
    	FILE *storage;
    
    	//Start timing the code
    	if(QueryPerformanceCounter((LARGE_INTEGER *)&ctr1) != 0)
    	{
    		storage = fopen("C:\\TestTimer.txt", "a"); //Open a file for data output
    		//Code segment is being timed
    		for(i=0; i<100; i++) acc++;
    		//Finish timing the code
    		QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
    
    		fprintf(storage, "Start Value %i\n", ctr1.ToString());
    		Console::WriteLine("Start Value: {0}",ctr1.ToString());
    
    		fprintf(storage, "End Value %i\n", ctr2.ToString());
    		Console::WriteLine("End Value: {0}",ctr2.ToString());
    
    		QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
    
    		fprintf(storage, "Frequency %i\n", freq.ToString());		
    Console::WriteLine(S"QueryPerformanceCounter minimum resolution: 1/{0} seconds.",freq.ToString());
    		fprintf(storage, "Time %i\n", ((ctr2-ctr1) * 1.0 / freq).ToString());		
    		Console::WriteLine("100 Increment time: {0} seconds.",((ctr2-ctr1) * 1.0 / freq).ToString());		fclose(storage);
    	} 	
    	return 0;
    }
    Thank You

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: QueryPerformance

    The fprintf function as far as i understand takes differnet variable types interrated them into the string and writes them to the file.

    You are telling fprintf that you are including an int, hence the %i, but you are passing a string, "ctr1.ToString()", It could be when it is converting from one type to another that the problem occurs. I have used C++ in ages so i could be wrong but try asking in that C/C++ forum.

    Hope that helps

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2004
    Posts
    60

    Re: QueryPerformance

    thanks for that help.

    That solved the problem. I thought it might be something simple.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width