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();
With generics, there's zero overhead. Your code will look something like
answer = optimizedRoutine<Type>();
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
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
This happens at run-time. There's an overhead.With generics, there's zero overhead. Your code will look something like
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