The Cost of a Closure in C: The Rest

(thephd.dev)

29 points | by ingve 3 days ago ago

10 comments

  • userbinator 4 hours ago ago

    Those graph axes units are... perplexing, to say the least.

    So, we need to swap to the logarithmic graphs to get a better picture

    I wish more people would know about decibels.

  • djaouen 4 hours ago ago

    Lisp solves the performance hit of closures with macros. However, given what macros look like in C, I hope it never amounts to that!

    • skavi 3 hours ago ago

      There’s no necessary performance hit for closures. The performance cost here is caused by these closures needing to conform to a function pointer looking interface in order to be generally useful in C.

  • Panzerschrek 4 hours ago ago

    Why struggling using qsort? std::sort from C++ is much better in terms of usability and performance.

    • pjmlp 26 minutes ago ago

      Because some people will never move beyond C, no matter what.

      • tliltocatl 14 minutes ago ago

        People will never move beyond C (among other reasons) because C allows precise control over memory allocation. Closures and precise control over memory allocation doesn't play very well together.

  • andsoitis 5 hours ago ago

    > Cost of a Closure in C

    C does not have closures. You could simulate closures, but it is neither robust not automatic compared to languages tha truly support them.

    • skavi 3 hours ago ago

      I think maybe this post would make more sense if you were familiar to its antecedent [0] which compares existing closure extensions to C. IIRC the comparison was in the context of considering designs for standardization.

      [0]: https://thephd.dev/the-cost-of-a-closure-in-c-c2y

    • aragilar 4 hours ago ago

      C does not currently have closures, the post it looking at their performance properties with an eye for what form closures should be added to the standard.

    • pjmlp 25 minutes ago ago

      Completely missed the point of the article, this is about ongoing C2y efforts at WG14.