6 ms·
Your comment makes me feel sad. It just reflects a whole mindset that makes me feel like an oppressed minority somehow. It sucks that most people don't really
by Negitivefrags 13y ago
Your comment makes me feel sad. It just reflects a whole mindset that makes me feel like an oppressed minority somehow.
It sucks that most people don't really care about performance any more. It sucks when people causally dismiss people who do care about performance with arguments like "premature optimization" and so on.
It kind of sucks that the web is taking over because it gives an excuse to use slow languages. It almost makes me feel sick to think that Javascript stores all numbers as doubles.
So you know what? It makes me feel happy to use the most efficient type that will work. I like my single precision floats.
I can die happy knowing that I didn't waste everyone's collective network, disks and CPUs with needless processing. Can't it be good to save just for the sake of saving?
So you want a practical reason do you?
I shaved over 2 gigabytes off the size off the download size of our product simply by using more efficient data types. Using half size floats is good enough for some data (16 bits).
And let me tell you about a data type that we used to use called a char. 8 bits would you believe! Turns out those x86 CPUs that are sitting there a few VMs deep still support those things.
- hvidgaard 13y agoIt's not even about performance. It's about actively thinking about what data you'd be processing. Why use doubles when singles are okay? I'd sure not be using 64 bit ints just because "it's bigger" when a normal 32 bit would be just fine.
- marcosdumay 13y ago> Why use doubles when singles are okay? Because of rounding issues, that look like a no problem for a single precision number, but will be a no problem^2 for a double precision one. Thus, if I'm wrong (or get wrong after a change in scope), the program will still work.
- cwp 13y agoWell, if you need more precision than singles provide, then yeah, use doubles. The question was, "why use doubles when singles are okay?"
- chii 13y agobut you didn't consider the other case, which imho, is more common - where you thought 1 char ought to be enough for anybody...until it isn't, and it's impossible to make it into a 32bit integer...
- hvidgaard 13y agoOnly when requirements have changed significantly, have I had to change the datatype. Either the input resolution are increased significantly, or the amount of data is several magnitudes larger than original specified, or higher precision is required. I tend to err on the side of selecting something larger if I'm uncertain. Consider a database: If expected data amounts to 10 inserts pr second, and the application lifetime is expected to be 10 years, 32-bit is enough to index. However, there is only room for 36% growth, so 64-bit it is, unless performance is important. In that case watch the index and project when it will run out of space. The point is, you consider the cases, and make an educated choice, this means reasoning about it both ways.
- jwmerrill 13y agoSorry for making you feel sad. Good points all around, here, and in the other comments about GPUs. Regarding CPU, though, my understanding is that on a 64 bit machine, 32 bit arithmetic is no faster than 64 bit arithmetic. Is that incorrect?
- hayfield 13y agoSome work I was doing over the summer indicates that the optimal datatype depends on the algorithm you're using. qsort() can get 15% better performance with uint64_ts than uint32_ts (sorting identical arrays of 8 bit numbers represented differently). On the other hand, a naive bubble sort implementation was managing 5% better performance with 16 bit datatypes over any of the others. If you start measuring energy usage as well, it becomes even stranger - using a different datatype can make it run 5% faster, while using 10%+ less energy (or in the qsort() case, take less time, but use more energy).
- nly 13y agoqsort strikes me as a bit of a crappy benchmark because of the type erasure. Your compiler likely isn't inlining or applying vectorisation. Vectorisation would likely benefit 32bit floats on a 64bit platform more than doubles.
- hayfield 13y agoIndeed - it probably isn't ideal. I'd tested a number of sort algorithms (bubble, insertion, quick, merge, counting), so also testing the sort function from stdlib seemed like a logical continuation. It was done rather quickly, so there wasn't time to properly investigate, merely look at the numbers and go "that's strange".
- sampo 13y agoWhat about 32 bit ints stored 64 bits away from each other?
- hayfield 13y ago
- lmm 13y ago> It sucks that most people don't really care about performance any more. It sucks when people causally dismiss people who do care about performance with arguments like "premature optimization" and so on. Why? Really. To my mind it's good that we no longer have to care about these implementation details, and can concentrate on writing code that expresses what we mean. Like writing on paper rather than scratching letters into tree bark.
- eliasmacpherson 13y agoWhat if your meaning is "run faster than a competitor"?
- lmm 13y agoWell, if you enjoy that then have fun with it. But I don't think you should bemoan the fact that most of us find other things more interesting.
- eliasmacpherson 13y agoWhat are these other things? This idea that other stuff is more interesting comes up on xkcd often enough. I have a hard time finding programs that don't push the computer interesting - media programs and so on interest me more than anything else. There's the top 1% of programs that people actually use and then there's a huge wasteland of stuff nobody uses. This top 1% usually have a lot of attention paid to their performance. I can think of websites that don't really demand computer power that are interesting but only as businesses - not as programs themselves. And they have performance requirements in the background.
- lmm 13y agoMy first job was a system for building interactive SMS services, balancing power and expressiveness with user-friendliness, much like designing a programming language. But since the mobile phone system itself adds so much latency, performance was rarely an issue. My third job was an insurance trading platform. Most of the interesting stuff was around the representation of contracts, making it possible to manipulate them by computer, and compare different possibilities, but still having them look like the paper contracts users were used to. My second job was at a music streaming service, and was mostly about doing simple things in ways that performed well, or scaled up to millions of users. I found this a lot less interesting or creative than my first or third job. Of course, that could just be personal taste.
- thedufer 13y ago> It almost makes me feel sick to think that Javascript stores all numbers as doubles. That's not actually true. JS engines are highly optimized. For example, anything that fits in a 32-bit int (and is an integer, of course) is stored as such, at least in V8.
- Gravityloss 13y agoEEGLab, a Matlab plugin used by brain researchers, at least used to use explicitly single precision floats for data series.