4 ms·
Common sense says that non-GC languages should beat GC languages, but there are actually cases where GCs can be faster. In particular, allocating memory can be
by captainmuon 9y ago
Common sense says that non-GC languages should beat GC languages, but there are actually cases where GCs can be faster. In particular, allocating memory can be just incrementing a pointer with a GC, whereas malloc does some more bookkeeping. You pay the price later during garbage collection, but if you are lucky your process is idle at that time, or even better, it is finished, and you get cleanup for free. See also https://stackoverflow.com/a/6977194/143091 https://stackoverflow.com/a/6977194/143091 What's faster will vary a lot from case to case.
(Of course, deep down the stack is always a non-GCed language, or at least assembly, so if your GC language wins a benchmark, you can always write that same program + the GC runtime in a non-GC language... but that is a trivial observation. Nim compiles to C, so is it GC'ed or not?)