3 ms·
the post goes in detail. Essentially, imagine you have custom routines for your ints and floats and your language doesn't support generics. You'll have a code
by b0sk 4y ago
the post goes in detail.
Essentially, imagine you have custom routines for your ints and floats and your language doesn't support generics. You'll have a code like this
if type is INT:
answer = optimizedRoutineForInt();
else type is FLOAT:
answer = optimizedRoutineForFloat();
This happens at run-time. There's an overhead.
With generics, there's zero overhead. Your code will look something like
answer = optimizedRoutine<Type>();
and if optimizedRoutine<Float> can be inlined at this site, there are no conditions or jumps in the code.
The post goes in detail about how for sorting, this sort of comparison function is called so frequently it has a massive impact on performance
- veidelis 4y ago..this comparison function of sort..