Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numerical optimization

I was wondering which Integer or Float types are the fastest..
i was thinking byte is faster than integer because it has a smaller range.
Some people told me .. that in some cases integer is faster than a byte.

second question :
The GPU is on his way to World Domination ..
so i asked myself : Can a Double "be faster" than a Integer .. because of the FPU
so where are the experts ? :)

like image 878
n00ki3 Avatar asked Dec 17 '22 09:12

n00ki3


1 Answers

You have to think about more than the clock cycles to carry out arithmetic. You could say that adding two ints takes this many cycles, adding two doubles takes this many cycles, etc. but that may not be relevant. If all your data fits into cache at the same time, then timing individual operations makes sense. But if not, the extra time required due to a cache miss dominates the difference in individual operations. Sometimes working with smaller data types is faster because it makes the difference between having to pull something from cache or not, or having to go to disk or not.

These days computers spend most of their time moving data around, not doing arithmetic, even in number crunching applications. And the ratio of the former to the latter is increasing. You can't simply compare, for example, the time needed to multiply shorts versus doubles. You might find that given two versions of your program, one version runs faster on a small problem and the other version runs faster on a larger program, all because of the relative efficiency of kinds of memory.

like image 101
John D. Cook Avatar answered Mar 11 '23 02:03

John D. Cook