PDA

Click to See Complete Forum and Search --> : QueryPerformance


wallacej
Feb 22nd, 2005, 10:42 AM
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???

#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

john tindell
Feb 22nd, 2005, 10:56 AM
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. (http://www.vbforums.com/forumdisplay.php?f=9)

Hope that helps

wallacej
Feb 22nd, 2005, 11:21 AM
thanks for that help.

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