I posted this comment:
"It's obvious that you're new to Node.js.<p>First of all, you should be aware that Async.js is a mere flow-control library. It does not offload work to separate threads, and neither is it able to parallelize work. Internally, it mostly does bean-counting (but very helpfully so).<p>As you can see in the source <a href="https://github.com/caolan/async/blob/master/lib/async.js#L359" rel="nofollow">https://github.com/caolan/async/blob/master/lib/async.js#L35...</a> async.sortBy simply uses Array.sort for the actual sorting. The only reason you'd want to use Async.sortBy is if the values that the array of "keys" is not known beforehand (and needed to be loaded through io - asynchronously). This is clearly exemplified in the documentation. <a href="https://github.com/caolan/async#sortBy" rel="nofollow">https://github.com/caolan/async#sortBy</a><p>The implication of this that your call to async.sortby can be replaced by a call to array.sort. This will remove two unnecessary runs of async.map, inflicting a potentially huge performance penalty.<p>You do need to pass array.sort a comparator function, otherwise it will sort lexicographically (see <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort" rel="nofollow">https://developer.mozilla.org/en-US/docs/JavaScript/Referenc...</a> ). That said, I'm not sure what the actual contents of your input file is. In your .Net example, you do not seem to bother to convert the array of strings to an array of ints (or floats). I think that .Net sort will sort an array of strings lexicographically as well. Furthermore, in the node.js example, you seem to be content with returning the resulting median as an int, not as float. Do the input "decimals" in the input file represent ints or floats? Do they all have exactly the same amount of decimals? Are both the Node.js and .Net algorithms doing the same thing? I think not.<p>Finally, we get to Array.sort. Array.sort blocks. Depending on the multi-threading efficiency of the underlying algorithm of Array.sort (which I don't have insight in), the code may not be able to use all available system resources. Keep in mind that Node.js is single-threaded. I practically don't know anything about .Net, but I assume it will magically start new processes and or threads if the runtime deems this beneficial. For Node.js, you may want to try the Cluster api, <a href="http://nodejs.org/api/cluster.html" rel="nofollow">http://nodejs.org/api/cluster.html</a> . You could try seeing if performance increases by adding one or more extra server processes.<p>I can't comment about the quality of the .net code since I don't have any experience with it.<p>I think it would be fair (and very educative to others) if you'd rerun the benchmarks with
1. Async.sortBy replaced with array.sort
2. with both .Net and Node.js algorithms fully doing the same thing (i.e. let them both sort either floats, ints, or strings), and
3. at least one extra server process for Node.
I think most interesting would be if you'd made the changes step-by-step, and run the benchmarks at each step.<p>My guess is that step 1 would give the biggest difference.
Depending on how you decide to resolve the differences in the two algorithms, performance of your .Net code may be slightly affected. It could potentially be speed up in fact, if somehow it's able to sort ints (or floats) faster than strings. The actual job of sorting probably overshadows it all though."<p>What do you guys think of this?