3 ms·
Ideally the temporary array should optimise away.
by chrisseaton 6y ago
Ideally the temporary array should optimise away.
- nitrogen 6y agoIdeally, but so far my experiences with simple benchmarks and with ruby-prof have shown that CRuby doesn't make such optimizations: https://repl.it/repls/GargantuanThistleLink https://repl.it/repls/GargantuanThistleLink Result from sort: 3 in 0.9785124980007822s Allocated 3000001 object(s) Result from ternary: 3 in 0.3205206830025418s Allocated 1 object(s) Result from clamp: 3 in 0.5030354310001712s Allocated 2 object(s) Interestingly the ternary comparison is faster than clamp.