# Benchmarks

MUL is measured by how many tokens it takes to get a task done correctly.
This page tracks the first part of that
metric: the size of the same program in MUL and in other languages. Each
program prints the same output and exits with the same code in every language
(`make compare` checks it). Shorter bars are fewer tokens.

<figure class="chart"><svg viewBox="0 0 720 838" role="img" aria-label="Token count of each program in MUL, Go, PHP, C and Rust; the table below has the same numbers"><text class="chart-label" x="100" y="44" text-anchor="end">abundant</text><g><title>abundant, MUL: 113 tokens</title><rect class="s1" x="112" y="8" width="328.3" height="11" rx="3"/><text class="chart-value" x="446.3" y="18">113</text></g><g><title>abundant, Go: 153 tokens (+35.4% vs MUL)</title><rect class="s2" x="112" y="21" width="444.5" height="11" rx="3"/><text class="chart-value" x="562.5" y="31">153</text></g><g><title>abundant, PHP: 163 tokens (+44.2% vs MUL)</title><rect class="s3" x="112" y="34" width="473.5" height="11" rx="3"/><text class="chart-value" x="591.5" y="44">163</text></g><g><title>abundant, C: 175 tokens (+54.9% vs MUL)</title><rect class="s4" x="112" y="47" width="508.4" height="11" rx="3"/><text class="chart-value" x="626.4" y="57">175</text></g><g><title>abundant, Rust: 143 tokens (+26.5% vs MUL)</title><rect class="s5" x="112" y="60" width="415.4" height="11" rx="3"/><text class="chart-value" x="533.4" y="70">143</text></g><text class="chart-label" x="100" y="127" text-anchor="end">collatz</text><g><title>collatz, MUL: 91 tokens</title><rect class="s1" x="112" y="91" width="264.4" height="11" rx="3"/><text class="chart-value" x="382.4" y="101">91</text></g><g><title>collatz, Go: 112 tokens (+23.1% vs MUL)</title><rect class="s2" x="112" y="104" width="325.4" height="11" rx="3"/><text class="chart-value" x="443.4" y="114">112</text></g><g><title>collatz, PHP: 121 tokens (+33.0% vs MUL)</title><rect class="s3" x="112" y="117" width="351.5" height="11" rx="3"/><text class="chart-value" x="469.5" y="127">121</text></g><g><title>collatz, C: 130 tokens (+42.9% vs MUL)</title><rect class="s4" x="112" y="130" width="377.7" height="11" rx="3"/><text class="chart-value" x="495.7" y="140">130</text></g><g><title>collatz, Rust: 116 tokens (+27.5% vs MUL)</title><rect class="s5" x="112" y="143" width="337.0" height="11" rx="3"/><text class="chart-value" x="455.0" y="153">116</text></g><text class="chart-label" x="100" y="210" text-anchor="end">digits</text><g><title>digits, MUL: 95 tokens</title><rect class="s1" x="112" y="174" width="276.0" height="11" rx="3"/><text class="chart-value" x="394.0" y="184">95</text></g><g><title>digits, Go: 124 tokens (+30.5% vs MUL)</title><rect class="s2" x="112" y="187" width="360.2" height="11" rx="3"/><text class="chart-value" x="478.2" y="197">124</text></g><g><title>digits, PHP: 131 tokens (+37.9% vs MUL)</title><rect class="s3" x="112" y="200" width="380.6" height="11" rx="3"/><text class="chart-value" x="498.6" y="210">131</text></g><g><title>digits, C: 144 tokens (+51.6% vs MUL)</title><rect class="s4" x="112" y="213" width="418.3" height="11" rx="3"/><text class="chart-value" x="536.3" y="223">144</text></g><g><title>digits, Rust: 119 tokens (+25.3% vs MUL)</title><rect class="s5" x="112" y="226" width="345.7" height="11" rx="3"/><text class="chart-value" x="463.7" y="236">119</text></g><text class="chart-label" x="100" y="293" text-anchor="end">fib</text><g><title>fib, MUL: 49 tokens</title><rect class="s1" x="112" y="257" width="142.3" height="11" rx="3"/><text class="chart-value" x="260.3" y="267">49</text></g><g><title>fib, Go: 65 tokens (+32.7% vs MUL)</title><rect class="s2" x="112" y="270" width="188.8" height="11" rx="3"/><text class="chart-value" x="306.8" y="280">65</text></g><g><title>fib, PHP: 58 tokens (+18.4% vs MUL)</title><rect class="s3" x="112" y="283" width="168.5" height="11" rx="3"/><text class="chart-value" x="286.5" y="293">58</text></g><g><title>fib, C: 71 tokens (+44.9% vs MUL)</title><rect class="s4" x="112" y="296" width="206.3" height="11" rx="3"/><text class="chart-value" x="324.3" y="306">71</text></g><g><title>fib, Rust: 58 tokens (+18.4% vs MUL)</title><rect class="s5" x="112" y="309" width="168.5" height="11" rx="3"/><text class="chart-value" x="286.5" y="319">58</text></g><text class="chart-label" x="100" y="376" text-anchor="end">fizzbuzz</text><g><title>fizzbuzz, MUL: 120 tokens</title><rect class="s1" x="112" y="340" width="348.6" height="11" rx="3"/><text class="chart-value" x="466.6" y="350">120</text></g><g><title>fizzbuzz, Go: 156 tokens (+30.0% vs MUL)</title><rect class="s2" x="112" y="353" width="453.2" height="11" rx="3"/><text class="chart-value" x="571.2" y="363">156</text></g><g><title>fizzbuzz, PHP: 165 tokens (+37.5% vs MUL)</title><rect class="s3" x="112" y="366" width="479.3" height="11" rx="3"/><text class="chart-value" x="597.3" y="376">165</text></g><g><title>fizzbuzz, C: 179 tokens (+49.2% vs MUL)</title><rect class="s4" x="112" y="379" width="520.0" height="11" rx="3"/><text class="chart-value" x="638.0" y="389">179</text></g><g><title>fizzbuzz, Rust: 155 tokens (+29.2% vs MUL)</title><rect class="s5" x="112" y="392" width="450.3" height="11" rx="3"/><text class="chart-value" x="568.3" y="402">155</text></g><text class="chart-label" x="100" y="459" text-anchor="end">gcd</text><g><title>gcd, MUL: 66 tokens</title><rect class="s1" x="112" y="423" width="191.7" height="11" rx="3"/><text class="chart-value" x="309.7" y="433">66</text></g><g><title>gcd, Go: 84 tokens (+27.3% vs MUL)</title><rect class="s2" x="112" y="436" width="244.0" height="11" rx="3"/><text class="chart-value" x="362.0" y="446">84</text></g><g><title>gcd, PHP: 89 tokens (+34.8% vs MUL)</title><rect class="s3" x="112" y="449" width="258.5" height="11" rx="3"/><text class="chart-value" x="376.5" y="459">89</text></g><g><title>gcd, C: 99 tokens (+50.0% vs MUL)</title><rect class="s4" x="112" y="462" width="287.6" height="11" rx="3"/><text class="chart-value" x="405.6" y="472">99</text></g><g><title>gcd, Rust: 85 tokens (+28.8% vs MUL)</title><rect class="s5" x="112" y="475" width="246.9" height="11" rx="3"/><text class="chart-value" x="364.9" y="485">85</text></g><text class="chart-label" x="100" y="542" text-anchor="end">hello</text><g><title>hello, MUL: 22 tokens</title><rect class="s1" x="112" y="506" width="63.9" height="11" rx="3"/><text class="chart-value" x="181.9" y="516">22</text></g><g><title>hello, Go: 22 tokens (+0.0% vs MUL)</title><rect class="s2" x="112" y="519" width="63.9" height="11" rx="3"/><text class="chart-value" x="181.9" y="529">22</text></g><g><title>hello, PHP: 15 tokens (-31.8% vs MUL)</title><rect class="s3" x="112" y="532" width="43.6" height="11" rx="3"/><text class="chart-value" x="161.6" y="542">15</text></g><g><title>hello, C: 25 tokens (+13.6% vs MUL)</title><rect class="s4" x="112" y="545" width="72.6" height="11" rx="3"/><text class="chart-value" x="190.6" y="555">25</text></g><g><title>hello, Rust: 14 tokens (-36.4% vs MUL)</title><rect class="s5" x="112" y="558" width="40.7" height="11" rx="3"/><text class="chart-value" x="158.7" y="568">14</text></g><text class="chart-label" x="100" y="625" text-anchor="end">isqrt</text><g><title>isqrt, MUL: 74 tokens</title><rect class="s1" x="112" y="589" width="215.0" height="11" rx="3"/><text class="chart-value" x="333.0" y="599">74</text></g><g><title>isqrt, Go: 103 tokens (+39.2% vs MUL)</title><rect class="s2" x="112" y="602" width="299.2" height="11" rx="3"/><text class="chart-value" x="417.2" y="612">103</text></g><g><title>isqrt, PHP: 110 tokens (+48.6% vs MUL)</title><rect class="s3" x="112" y="615" width="319.6" height="11" rx="3"/><text class="chart-value" x="437.6" y="625">110</text></g><g><title>isqrt, C: 114 tokens (+54.1% vs MUL)</title><rect class="s4" x="112" y="628" width="331.2" height="11" rx="3"/><text class="chart-value" x="449.2" y="638">114</text></g><g><title>isqrt, Rust: 99 tokens (+33.8% vs MUL)</title><rect class="s5" x="112" y="641" width="287.6" height="11" rx="3"/><text class="chart-value" x="405.6" y="651">99</text></g><text class="chart-label" x="100" y="708" text-anchor="end">power</text><g><title>power, MUL: 108 tokens</title><rect class="s1" x="112" y="672" width="313.7" height="11" rx="3"/><text class="chart-value" x="431.7" y="682">108</text></g><g><title>power, Go: 133 tokens (+23.1% vs MUL)</title><rect class="s2" x="112" y="685" width="386.4" height="11" rx="3"/><text class="chart-value" x="504.4" y="695">133</text></g><g><title>power, PHP: 146 tokens (+35.2% vs MUL)</title><rect class="s3" x="112" y="698" width="424.1" height="11" rx="3"/><text class="chart-value" x="542.1" y="708">146</text></g><g><title>power, C: 148 tokens (+37.0% vs MUL)</title><rect class="s4" x="112" y="711" width="429.9" height="11" rx="3"/><text class="chart-value" x="547.9" y="721">148</text></g><g><title>power, Rust: 132 tokens (+22.2% vs MUL)</title><rect class="s5" x="112" y="724" width="383.5" height="11" rx="3"/><text class="chart-value" x="501.5" y="734">132</text></g><text class="chart-label" x="100" y="791" text-anchor="end">primes</text><g><title>primes, MUL: 106 tokens</title><rect class="s1" x="112" y="755" width="307.9" height="11" rx="3"/><text class="chart-value" x="425.9" y="765">106</text></g><g><title>primes, Go: 143 tokens (+34.9% vs MUL)</title><rect class="s2" x="112" y="768" width="415.4" height="11" rx="3"/><text class="chart-value" x="533.4" y="778">143</text></g><g><title>primes, PHP: 153 tokens (+44.3% vs MUL)</title><rect class="s3" x="112" y="781" width="444.5" height="11" rx="3"/><text class="chart-value" x="562.5" y="791">153</text></g><g><title>primes, C: 164 tokens (+54.7% vs MUL)</title><rect class="s4" x="112" y="794" width="476.4" height="11" rx="3"/><text class="chart-value" x="594.4" y="804">164</text></g><g><title>primes, Rust: 134 tokens (+26.4% vs MUL)</title><rect class="s5" x="112" y="807" width="389.3" height="11" rx="3"/><text class="chart-value" x="507.3" y="817">134</text></g><line class="chart-axis" x1="112" y1="4" x2="112" y2="834"/></svg><figcaption><span class="key s1">MUL</span><span class="key s2">Go</span><span class="key s3">PHP</span><span class="key s4">C</span><span class="key s5">Rust</span></figcaption></figure>

## Numbers

Tokens per file; in brackets, the difference to the MUL version.

| Program | MUL | Go | PHP | C | Rust |
|---|--:|--:|--:|--:|--:|
| [abundant](/examples/compare-abundant/) | 113 | 153 (+35.4%) | 163 (+44.2%) | 175 (+54.9%) | 143 (+26.5%) |
| [collatz](/examples/compare-collatz/) | 91 | 112 (+23.1%) | 121 (+33.0%) | 130 (+42.9%) | 116 (+27.5%) |
| [digits](/examples/compare-digits/) | 95 | 124 (+30.5%) | 131 (+37.9%) | 144 (+51.6%) | 119 (+25.3%) |
| [fib](/examples/compare-fib/) | 49 | 65 (+32.7%) | 58 (+18.4%) | 71 (+44.9%) | 58 (+18.4%) |
| [fizzbuzz](/examples/compare-fizzbuzz/) | 120 | 156 (+30.0%) | 165 (+37.5%) | 179 (+49.2%) | 155 (+29.2%) |
| [gcd](/examples/compare-gcd/) | 66 | 84 (+27.3%) | 89 (+34.8%) | 99 (+50.0%) | 85 (+28.8%) |
| [hello](/examples/compare-hello/) | 22 | 22 (+0.0%) | 15 (-31.8%) | 25 (+13.6%) | 14 (-36.4%) |
| [isqrt](/examples/compare-isqrt/) | 74 | 103 (+39.2%) | 110 (+48.6%) | 114 (+54.1%) | 99 (+33.8%) |
| [power](/examples/compare-power/) | 108 | 133 (+23.1%) | 146 (+35.2%) | 148 (+37.0%) | 132 (+22.2%) |
| [primes](/examples/compare-primes/) | 106 | 143 (+34.9%) | 153 (+44.3%) | 164 (+54.7%) | 134 (+26.4%) |

## How it is measured

The counts come from the offline estimate built into `mul tokens`: it is
deterministic and sends no code anywhere. Its rules are fitted to GPT-style
BPE tokenizers, which it matches within about 5% per file on the pilot
sample, but it is not the tokenizer of any particular model, so treat the
differences as a direction, not an exact figure.
`mul tokens --tokenizer-cmd` counts with a tokenizer of your choice.

Run-time speed is not compared here. The interpreter and the Cranelift backend
are checked to give the same results, not tuned for speed, so a timing table
against Go or C would say little about the language at this stage.
