simeonz wrote: |
---|
Looks yummy except for the alignment of the braces. You must be using some of those exotic editors Duoas... |
I abhor most IDEs.
I am familiar with quite a few different languages, and my brace style reflects that. I've developed and used it for over 20 years. When writing personal software, I use a style that I find easy to read.
In the C/C++ world's nomenclature, what I use is most closely identified with Whitesmith's style.
rapidcoder wrote: |
---|
Even faster would be to load the file in smaller chunks fitting in the L1 or L2 cache (e.g. in 64 kB blocks), and process each block at a time, forming a pipeline (and destroying the blocks after they are processed). Loading the raw data into RAM entirely is just wasting the memory and also wasting the L2 cache. |
Yes, I was considering suggesting that as well, but we'll see what kind of hoops the OP wants to jump after he gets a handle on this. I don't consider the speed gains from fully loading the file to be any sort of waste, considering the whole file only takes about 800-900 megabytes, beyond which, it obviously isn't a fully-developed answer.
I admit that my knowledge of L2 caching and the like is limited, but I have no interest in playing compiler.
[edit] Sigh:
I really don't want to rehash this again.
Your arguments are wrong, and frankly, they expose you for your lack of knowledge. You've been brainwashed into believing crap by anti-C++ propaganda.
istringstream inherits from istream, and can be passed as one. The >> operator is a virtual function. |
The extraction operator is
not a virtual function. (Duh!) It may
use virtual functions, but its exact character is resolved at, pause for halo sound,
compile time. That's what templates do for you. Pretty swell stuff, ain't it?
Therefore the vtable slows you down. |
It has
very minimal impact.
Additionally, in code like f >> x >> y; the compiler cannot know that f >> x is the same reference as f. |
Why would the compiler care? The fact is that f >> x might
not be the same as f.
Further, the istringstream must check on various settings before doing anything, whereas strtof just assumes everything is fine. |
This argument is stupid in
four ways. One, strtof() doesn't deal with streams, just addressable memory. Two, the istringstream only needs to "check on various settings" once before doing anything, and O(1) is nothing. Three, strtof() does
not assume everything is fine. It has very complete error checking, just like the istringstream. Four, saying mystringstream >> myfloat is nearly identical to saying myfloat = strtof( mystring, ... ) -- oh, except for all the compiler protections against stupid stuff and guarantees against buffer overrun.
Finally, in f >> x x is passed by reference (invisible pointer). Therefore x must be in *memory*, not a register, which slows you down. |
Not necessarily. The whole point of references is really sweet optimizations that you don't see.
In x = strtof(s,NULL); x is returned using the floating point stack. |
So? istringstream has to use the FPU also. And that fancy reference optimization may actually keep the reference on the FPU stack, too.
In general, the C library ways of doing things are faster, more suited to the machine, but less extensible and less safe. |
That's all true except for the part about 'faster'. (Well, maybe not the "more suited to the machine" bit either, but that's another argument.)
I would, instead of a vector or deque or whatever, use a simple malloc, or maybe mmap,to make an array. This is guaranteed not to have any time-wasting checks of things. |
Only if you consider secure software to be a waste of time. Fortunately, all these "checks of things" you are so worried about are very few, and very cheap, and they can make your software so much more robust.
The problem is, even if you just told vector to be 10 ints long, v[1]=7; *still* checks if 0<=1<10. |
Actually, it doesn't. The standard is pretty specific on this point.
http://www.cplusplus.com/reference/stl/vector/operator%5B%5D/
Iterators do that too. In fact, if v is a vector and a is an array (of ints), v[1] is a function call, which means at minumum [nonsense about second guessing the compiler] |
Well then, go write in assembly. Chances are my compiler will do a better job than you. The
actual fact is that iterators are very highly optimizable, much more than you think. Oh, and v[1] is not likely a function call at all, because it is easily inlined. Even if it were, the performance hit, again, is so insignificant that you are wasting breath. This false argument has been put to rest so many times that it is amazing that people still breath it.
Bottom line, by its very *nature*, idiomatic C++, with STL, virtual functions, and safety, is slower than idiomatic C, with libc, arrays, and horrible unsafe optimizations. |
No, the bottom line is that the way you use it is fast or slow.
Here's something I bet you didn't know. A lot of older STL implementations used to just be a wrapper around C library calls. Now that it has matured, a lot of implementations, like Dinkumware and STLPort, don't bother with the C library because it is so flippin' s-l-o-w. Used properly, the STL blows the pants off of the C standard libary.
Don't believe me?
How about experts in the field.
Here's one:
http://www.daniweb.com/forums/thread40450.html
I'm sure you can find more:
http://www.google.com/search?q=iostream+vs+stdio
Seems you forgot about this thread:
http://www.cplusplus.com/forum/general/31527/
/me waits for the extremist anti-C++|anti-me verbiage to start
I'm glad it is so common to come to the forums lately and engage in such a pleasant exchange of ideas and solutions. Makes me want to wretch how abusive some of your language is towards each other.