Updated benchmark that fixes value range discrepancies between the F# and TypeScript benchmark: hamy.xyz/labs/2023-08-fsharp-vs-typescript-sort-performance-round-2 Results: F# still wins overall, but TS performs a bit better in its number sorting
Your benchmarks comparing the sorting of numbers are a bit misleading because the F# and TS code for `getRandomPositiveInteger()` return different ranges of integers. F#'s implementation returns integers 0 - 2147483647 (2^31 - 1), meanwhile the TS implementation returns integers 0 - 1.798e+308 (2^1024 - 1). Not only does this significantly decrease the chance of pre-sorted segments/runs occurring naturally in the random array, but it also has a significant runtime impact because Node (V8) numbers greater than 2^31 - 1 are heap allocated, as opposed to stack or register allocated (as it is in F#). Therefore, most numbers in your TS benchmark are actually getting heap allocated, which are obviously a lot slower to read from memory. But when I rerun your the TS benchmark with numbers in the same range as F#, the 1 million numbers case only takes 400ms on average on my 2018 Macbook Pro.
Wow good catch! That would make a lot of sense, was worried something was wrong when TS kept sorting numbers so slowly. Updating Replit runs to try and fix.
Okay updated the benchmarks and reran. TS is performing 4-8x faster than previously in its number sorting though other data types don't show much difference. F# still faster overall for sorting numbers. Results: hamy.xyz/labs/2023-08-fsharp-vs-typescript-sort-performance-round-2
Updated benchmark that fixes value range discrepancies between the F# and TypeScript benchmark: hamy.xyz/labs/2023-08-fsharp-vs-typescript-sort-performance-round-2
Results: F# still wins overall, but TS performs a bit better in its number sorting
F# performance? I'm here for it!
100% means 2 times faster, not 10 times
Your benchmarks comparing the sorting of numbers are a bit misleading because the F# and TS code for `getRandomPositiveInteger()` return different ranges of integers. F#'s implementation returns integers 0 - 2147483647 (2^31 - 1), meanwhile the TS implementation returns integers 0 - 1.798e+308 (2^1024 - 1). Not only does this significantly decrease the chance of pre-sorted segments/runs occurring naturally in the random array, but it also has a significant runtime impact because Node (V8) numbers greater than 2^31 - 1 are heap allocated, as opposed to stack or register allocated (as it is in F#). Therefore, most numbers in your TS benchmark are actually getting heap allocated, which are obviously a lot slower to read from memory. But when I rerun your the TS benchmark with numbers in the same range as F#, the 1 million numbers case only takes 400ms on average on my 2018 Macbook Pro.
Wow good catch! That would make a lot of sense, was worried something was wrong when TS kept sorting numbers so slowly.
Updating Replit runs to try and fix.
Okay updated the benchmarks and reran. TS is performing 4-8x faster than previously in its number sorting though other data types don't show much difference. F# still faster overall for sorting numbers.
Results: hamy.xyz/labs/2023-08-fsharp-vs-typescript-sort-performance-round-2