View Full Version : sscanf incredibly slow !
07-23-2001, 01:14 AM
I'm writing an ASE loader and I actually use sscanf, like this :
sscanf (WhereToRead, "%d %f %f %f", &j, &x, &y, &z);
But it's amazingly slow : just 200 calls (one per vertex) can take several seconds !
I've also tried replacing it by calls to strtol and strtod, but it's even worse !
Have you got any idea ?
Rob The Bloke
07-23-2001, 04:57 AM
I doubt sscanf is the problem. I'm presuming here that you read a line from the text file and put it into a large array from which you then use sscanf on. This doesn't cause speed problems.
From my experiance, slowness of the loader is to do with data storage and allocations. If you are storing your vertices on a linked list for example, that will cause large slowdown. You'd be doing a memory allocation for each vertex, nasty - always use arrays.
The other thing to look for would be memory leaks.
07-23-2001, 05:20 AM
I do use arrays ! And however i've checked that when loading large meshes, quite all the time is spent in sscanf.
I've seen Plib, it's very fast. Should I look down in the thousands of lines of code of Plib and then copy-paste ?
Plib uses strtol/strtod. But when I do, it's even slower than sscanf. Why ?
Please help !
[This message has been edited by Morglum (edited 07-23-2001).]
07-23-2001, 02:08 PM
I've solved my problem myself. The solution lied in tokenization, using strtok. Thanks !
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.