Slow performance with new 3GHz Machine using FlushFileBuffers

P

Pedro Salazar

Hi,

I have a new machine with Intel Desktop Board D865GBF. 3GHz. A simple
program like this (I explain later) takes TEN times more to complete
than in my older machine with 1.7GHz, D850MV.

Same system (Windows 2000), same installed software, same hard disk
(IDE), same configuration.

I have tried with other hard disks, same result.

Note: if I withdraw the FlushFileBuffers function call, I have a
little better result in my new machine. I need to use this call or
something similar to asure data saving. (at least in the system's
buffer)

I've updated the last Intel BIOS without succesful result. I think the
disk is working fine, all benchmarks with the hard disk are so good in
my new machine as in the old.

Thanks in advance for any help.

Here the program:

#include "stdafx.h"
#include <stdio.h>
#include <io.h>
#include <windows.h>

int main(int argc, char* argv[])
{
FILE *m_file;
unsigned long i;
HANDLE hfile;

m_file = fopen ("testf", "r+b");
if (!m_file)
m_file = fopen ("testf", "w+b");
if (!m_file)
return 1;
hfile = (HANDLE) _get_osfhandle (_fileno (m_file));
for (i=0; i< 20000;++i)
{
fwrite ("d", 1, 1, m_file);
FlushFileBuffers (hfile);
}
return 0;
}

Old machine: 2 seconds.
New machine: 20 seconds.
 
E

Erik S. Bartul

if im not mistaken, the standard guarentees all file handles to be closed
upon program exist, and subsequently all buffers will be flushed.
 
R

Richard Heathfield

Pedro said:
Hi,

I have a new machine with Intel Desktop Board D865GBF. 3GHz. A simple
program like this (I explain later) takes TEN times more to complete
than in my older machine with 1.7GHz, D850MV.

On my Linux machine, it doesn't even compile. Please leave comp.lang.c and
comp.lang.c++ off your list of crossposts when discussing platform-specific
code. Thanks.
 
C

CBFalconer

Pedro said:
I have a new machine with Intel Desktop Board D865GBF. 3GHz. A simple
program like this (I explain later) takes TEN times more to complete
than in my older machine with 1.7GHz, D850MV.

Same system (Windows 2000), same installed software, same hard disk
(IDE), same configuration.
.... snip ...

#include "stdafx.h"
^^^^^^^^ Unknown file
#include <stdio.h>
#include <io.h> ^^^^ Non standard file
#include <windows.h> ^^^^^^^^^ Non-standard file

int main(int argc, char* argv[])

This is neither a C nor a C++ program, as defined for those
newsgroups. They deal ONLY with ISO standard, fully portable,
programs. Follow-ups set.
 
E

E. Robert Tisdale

Pedro said:
I have a new machine with Intel Desktop Board D865GBF. 3GHz.

A simple program like this (I explain later)
takes TEN times [longer] to complete
than in my older machine with 1.7GHz, D850MV.

Same system (Windows 2000), same installed software,
same hard disk (IDE), same configuration.

I have tried with other hard disks, same result.

Note: if I withdraw the FlushFileBuffers function call,
I have a little better result in my new machine.

But not TEN times better?
I need to use this call or something similar

Like fflush(m_file)
to [en]sure data saving (at least in the system's buffer).

I've updated the last Intel BIOS without successful result.
I think the disk is working fine, all benchmarks

But *not* hard disk drive benchmarks?
with the hard disk are [as] good in my new machine as in the old.

Thanks in advance for any help.

Here the program:

#include "stdafx.h"
#include <stdio.h>
#include <io.h>
#include <windows.h>

int main(int argc, char* argv[]) {

FILE* m_file = fopen("testf", "r+b");
if (!m_file)
m_file = fopen("testf", "w+b");
if (!m_file)
return 1;
HANDLE hfile = (HANDLE)_get_osfhandle(_fileno(m_file));
for (unsigned int i=0; i< 20000;++i) {
fwrite("d", 1, 1, m_file);
FlushFileBuffers(hfile);
}
return 0;
}

Old machine: 2 seconds.
New machine: 20 seconds.

There is *nothing* wrong with the above program
(except that you write one character at a time to your disk drive).
Most probably, you haven't configured your new system
to take advantage of the disk cache
the way that your your old system did.
 
E

E. Robert Tisdale

CBFalconer said:
Pedro said:
#include "stdafx.h"

^^^^^^^^ Unknown file
#include <stdio.h>
#include <io.h>

^^^^ Non standard file
#include <windows.h>

^^^^^^^^^ Non-standard file
int main(int argc, char* argv[])

This is neither a C nor a C++ program,
as defined for those newsgroups.
They deal ONLY with ISO standard, fully portable,
fully portable, programs.

Nonsense! Where is it written that
"Only standard header files may be included in C or C++ programs?"
cat windows.h
cat stdafx.h
cat io.h
typedef FILE* HANDLE;

inline
HANDLE _fileno(FILE* fp) {
return (HANDLE)fp;
}

inline
HANDLE _get_osfhandle(HANDLE h) {
return h;
}

inline
int FlushFileBuffers(HANDLE h) {
return fflush((FILE*)h);
}
gcc -Wall -std=c99 -pedantic -I. -o pedro pedro.c
time ./pedro
0.019u 0.060s 0:00.08 87.5% 0+0k 0+0io 79pf+0w
gcc --version
gcc (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
 
C

Christian Bau

Note: if I withdraw the FlushFileBuffers function call, I have a
little better result in my new machine. I need to use this call or
something similar to asure data saving. (at least in the system's
buffer)

I think you should rethink your strategies for saving data.

You should also rethink your strategies of posting stuff that is
completely off-topic in at least three of the four newsgroups.
 
E

E. Robert Tisdale

Christian said:
You should also rethink your strategies of posting stuff that is
completely off-topic in at least three of the four newsgroups.

You should rethink your strategies of cross-posting replys to stuff
that is completely off-topic in at least three of the four newsgroups.
 
P

Pedro Salazar

Richard Heathfield said:
On my Linux machine, it doesn't even compile. Please leave comp.lang.c and
comp.lang.c++ off your list of crossposts when discussing platform-specific
code. Thanks.

Thank you too, I was hoping someone with experience in C and Windows
2000 could give me another way to get the same result. If this is not
the place to search that advice please tell me where. Thanks.
 
R

Richard Bos

E. Robert Tisdale said:
Nonsense! Where is it written that
"Only standard header files may be included in C or C++ programs?"

Nowhere. But C programs that do are no longer defined by the
Standard(s), and therefore off-topic in comp.lang.c.

The contents of headers on your broken system is of no interest to a
group dedicated to portable programming.

Richard
 
R

Randy Howard

psalazar@datatec- said:
Thank you too, I was hoping someone with experience in C and Windows
2000 could give me another way to get the same result. If this is not
the place to search that advice please tell me where. Thanks.

Something in the comp.os.ms-windows.* hierarchy is a good place to start.
 
E

E. Robert Tisdale

Richard said:
The contents of headers on your broken system is of no interest
to a group dedicated to portable programming.

Perhaps.
But where is it written that either the comp.lang.c or comp.lang.c++
newsgroup is "dedicated to portable programming"?

Or did you accidentally post to the wrong newsgroups?
 
D

Default User

Alan said:
Also, it's been written in the newsgroup many times, and should be
obvious to anyone who has spent any time observing the group before
posting to it.


And who has a modicum of sense, which leaves Trollsdale in the dust.




Brian Rodenborn
 
E

E. Robert Tisdale

Alan said:
Also, it's been written in the newsgroup many times

Please cite and quote the article which asserts that,

"The comp.lang.c newsgroup is dedicated to portable programming".
and should be obvious to anyone who has spent any time
observing the group before posting to it.

I have been "observing" almost as long as these newsgroups have existed
and it is *not* obvious to me.
 
C

CBFalconer

Alan said:
Also, it's been written in the newsgroup many times, and should
be obvious to anyone who has spent any time observing the group
before posting to it.

I suggest ignoring Trollsdale entirely unless he performs his
trick of misquoting others or his alleged 'advice' is obviously
bad and misleading.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top