🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4567

Re: Faster FILE subroutines in standard C?

#4567
From: J. Kanze
Date: Fri, 05 Jan 1996 12:05
36 lines
2166 bytes
Kenneth Kafieh (ken@yorku.ca) wrote:

|> I found that I was able to get 3-4 time faster performance by using good 
|> old ANSI C file accessing routines (like  fgets, fseek, ftell, ...etc.)
|> instead of C++ streams (like ifstream::getline, fstream::seekg, ...etc.)
|> I wrote the program originally in C++ (a simple little phonebook for my
|> own use) and it took about 9 seconds to scan a 100Kb file for a 3 byte
|> string!!!  Fed up, I rewrote it in C and voila! Now it takes 2 secs!
|> I'm using Borland C++ v2.0.

|> Does that sound right?  Maybe my code was inefficiently written?
|> I know C++ is generally slower than C but I didn't think that 
|> file stuff would be too.   What did I do wrong? Am I missing
|> something.  Maybe I'll post the code too, later. Has anyone
|> else noticed this too?

This depends on the implementation.  With g++ 2.7.2 (libg++ 2.7.1), for
example, formatted output with iostream is more than twice as fast as
using fprintf.

|> Come to think of it, the coding in
|> C was cleaner looking, too.  

And more error prone (putting on my abestos suit).

More to the point: I'm currently reading this in comp.std.c, so I would
guess that iostream is irrelevant, off-topic, and doesn't necessarily
interest all of the readers.  In C, you don't have the choice.  (The
same article was posted to comp.lang.c++.moderated, where it is
relevant.  I would suggest that anyone wishing to follow up to this
posting do so there.)
-- 
James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils, études et réalisations en logiciel orienté objet --
              -- A la recherche d'une activité dans une region francophone
Technical Details
Message-ID: <4cj473$n0m@gabi.gabi-soft.fr>
Path: arc1-ca.pugleaf.net!gabi-soft.fr!not-for-mail
References: <4cfm7c$dot@sunburst.ccs.yorku.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!gabi-soft.fr!not-for-mail
From: kanze@gabi-soft.fr (J. Kanze)
Newsgroups: comp.std.c
Subject: Re: Faster FILE subroutines in standard C?
Date: 5 Jan 1996 13:05:55 +0100
Organization: GABI Software, Sarl.
Message-ID: <4cj473$n0m@gabi.gabi-soft.fr>
References: <4cfm7c$dot@sunburst.ccs.yorku.ca>
NNTP-Posting-Host: gabi.gabi-soft.fr
X-Newsreader: TIN [version 1.2 PL2]