W
wallacej
Hello
Can anybody explain to me why the following four FPRINTF lines of code
yield different results to their Console counterparts on the next line?
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 Console 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 fprintf 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;
}
Can anybody explain to me why the following four FPRINTF lines of code
yield different results to their Console counterparts on the next line?
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 Console 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 fprintf 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;
}