<story><title>Accidentally quadratic: When Python is faster than C++</title><url>https://arxiv.org/abs/1911.12338</url></story><parent_chain><item><author>IgorPartola</author><text>I’ve been thinking about this lately. Can you actually be faster than C? Like, in the sense that you can transpile any bit of Python or Lisp or Haskell or Rust or JS into C but the opposite isn’t necessarily true because not all those language support all the features exposed in C (such as goto, no bounds checking, pointer arithmetic, etc.), any algorithm for say parsing JSON can be expressed equally as efficiently in C, while a clever and hacky C-specific algorithm cannot necessarily be expressed in those higher level languages.&lt;p&gt;In other words, is “faster than C” even a good metric if all it means that “if you implement something inefficiently in C it will be faster than if it is implemented efficiently in not-C”?</text></item></parent_chain><comment><author>WalterBright</author><text>&amp;gt; Can you actually be faster than C?&lt;p&gt;Sure, in any language that provides more semantic information than C does. For example, D enables a &amp;quot;pointer to immutable data&amp;quot; type, while C does not. This can improve optimization.&lt;p&gt;On a pragmatic note, C makes it easy to use 0-terminated strings, and clumsy to use length-terminated strings. The natural result is people use 0-terminated strings.&lt;p&gt;0-terminated strings are inefficient because of the constant need to strlen them. When I look to optimize C, I find plenty of paydirt in all the strlen instances. D makes it easy to use length-terminated strings, and so people naturally prefer them.</text></comment>
<story><title>Accidentally quadratic: When Python is faster than C++</title><url>https://arxiv.org/abs/1911.12338</url></story><parent_chain><item><author>IgorPartola</author><text>I’ve been thinking about this lately. Can you actually be faster than C? Like, in the sense that you can transpile any bit of Python or Lisp or Haskell or Rust or JS into C but the opposite isn’t necessarily true because not all those language support all the features exposed in C (such as goto, no bounds checking, pointer arithmetic, etc.), any algorithm for say parsing JSON can be expressed equally as efficiently in C, while a clever and hacky C-specific algorithm cannot necessarily be expressed in those higher level languages.&lt;p&gt;In other words, is “faster than C” even a good metric if all it means that “if you implement something inefficiently in C it will be faster than if it is implemented efficiently in not-C”?</text></item></parent_chain><comment><author>btilly</author><text>FORTRAN is faster for many tasks, and is probably more popular in high performance computing.&lt;p&gt;Also tasks that can be moved to the GPU go a lot faster.  You can interact with those programs in C, but not natively.  But some languages, like Julia, can easily move calculations to&amp;#x2F;from the GPU.  And also can transparently take advantage of parallelism.&lt;p&gt;Julia is in the process of growing rapidly for high performance computing.  I don&amp;#x27;t know if it has officially passed C there.  But if not yet, it will.</text></comment>