gergoerdi / functional-mos6502-web-performance

https://unsafeperform.io/blog/2022-07-02-a_small_benchmark_for_functional_languages_targeting_web_browsers/
https://unsafeperform.io/blog/2022-07-02-a_small_benchmark_for_functional_languages_targeting_web_browsers/
27 stars 5 forks source link

Add a Clean implementation #5

Closed camilstaps closed 2 years ago

camilstaps commented 2 years ago

tl;dr: this adds an implementation in Clean which can be interpreted in WebAssembly. Benchmark result corrected for machine differences is 52.79ms; significantly slower than Idris but faster than TypeScript and Asterius. Code size is average.


I don't know if you're interested in pull requests for other languages, so feel free to ignore this. However, when I saw this project announced on the Haskell Weekly I thought it could be a nice larger benchmark to compare the WebAssembly interpreter for Clean with backends for other languages. Of course, it should be noted that this is an interpreter backend and the others are (AFAIK) all compilers.

Clean is a functional programming language similar to Haskell. It compiles through an intermediate language for an abstract machine based on graph rewriting, the ABC machine. It is possible to run Clean in the browser through WebAssembly with an interpreter for the ABC machine. For more details, see the interpreter repository and doi:10.1145/3412932.3412941.

Some notes about the implementation:

I compared my results with the JavaScript implementation, which was the easiest to set up for me. This gives 1.61ms for JavaScript and 40.09ms for Clean. The time reported for JavaScript on your blog is 2.12ms, so corrected for that Clean has 2.12/1.61*40.09 = 52.79ms.

Some other notes:

gergoerdi commented 2 years ago

Any idea why I might be unable to build this on a fresh install of Clean and Nitril?

Never mind, turns out I had clm installed in my $HOME/bin from back in 2008 when I last played with it at uni :D

gergoerdi commented 2 years ago

Good stuff. Merged in c4bab9076ab8fef9ae4cd9256fed4b402ab7dd46. For what it's worth, I'm seeing 40ms; but then again, if you look at my blogpost, I also had to update the JS number because for some reason I see faster numbers now...

camilstaps commented 2 years ago

Cool, thanks!