×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Generally I will use the POSIX API instead of STD C APIs. You can adjust it while appropriate latency but basically the Standard C (fwrite ()) API has own buffer where the data is copied and only then is written to disk.
I made small tests (similar to your program) and the POSIX API was much faster as the Standard C APIs.
Try to replace the fopen () and fwrite () with open () and write() ?
My tests in (clocks):
Loop writes with 2000 max 9000 char buffer
Write STD C: 69
Write POSIX: 28
Loop 90 000 writes with 2000 char buffer
Write C STD: 687
Write POSIX: 257
void writePOSIX()
{
int i, file;
file = open("/tmp/1.txt", O_CREAT|O_RDWR, S_IWUSR);
-----Original Message-----
From: c400-l-bounces+peter.daransky=uc4.com@xxxxxxxxxxxx [mailto:c400-l-bounces+peter.daransky=uc4.com@xxxxxxxxxxxx] On Behalf Of Boris
Sent: Dienstag, 24. Mai 2011 05:21
To: c400-l@xxxxxxxxxxxx
Subject: Re: [C400-L] C400-L Digest, Vol 9, Issue 22
Thanks for the quick response.
I'm probably missing on some basics here.
Here is a sample code:
for (i=0;i<=2000;i++)
buf[i]='c';
out = fopen("fileout.txt","w");
/*out = fopen("fileout.txt","wb,type=record,lrecl=2000");*/
for (i=0;i<=900000;i++)
{
num = fwrite (buf, 1, sizeof(buf), out );
}
fclose(out);
I removed the read function. It was populating the buf.
This program takes about 90% CPU.
I also tried:
num = fwrite (buf, sizeof(buf), 1, out ); It did reduce the CPU to about 85%. Then I increased the size of the buf to
10000 assuming it would further reduce the CPU but it instead jumped to 94%.
How do I make the program write by records/blocks? The commented line
doesn't work - fopen returns NULL.
Thanks.
Boris.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.