Version: v0.8.0 - Beta.  We welcome contributors & feedback.

Performance Benchmarks

Last updated: 2024-09-24

Overview

This benchmark compares the performance of THT versus the most popular PHP framework: Laravel.

Why compare a language to a framework?

1) THT takes a “batteries included” approach by providing essential web framework features.

2) Some might be worried that running a transpiled language would be too slow to run in production, and Laravel is arguably the best example of a production-ready PHP framework.

Task

// URL
/benchmark/route/1234

What does this test?

  1. The overhead of running the framework or language
  2. URL routing
  3. Template system

The Environment

Benchmark Runner

ab -k -c 10 -n 1000 http://localhost:8080/benchmark/route/1234

Benchmark Results

Framework Requests/sec (More = Faster)
Laravel 352
THT 5,188

Takeaway

THT performed significantly better than Laravel.

If you’re interested in using THT, you can be reasonably confident that it will be fast enough for most use cases.

Benchmark Code 

Laravel

file: routes/web.php
<?php

use Illuminate\Support\Facades\Route;

Route::get('/benchmark/route/{pid}', function () {

    $pid = Route::current()->parameter('pid');

    for ($i = 1; $i <= 100; $i += 1) {
        $item = [
            'num'  => $i,
            'name' => $pid . $i,
        ];
        $items[] = $item;
    }

    return view('welcome', ['pid' => $pid, 'items' => $items]);

});
file: resources/views/welcome.blade.php
<!doctype html>
<html>
    <head>
        <title>Route Param Test</title>
    </head>
    <body>
        LAR - Route Param: {{ $pid }}
        <ul>
            @foreach ($items as $item)
                @include('item', $item)
            @endforeach
        </ul>
    </body>
</html>
file: resources/views/item.blade.php
<li>{{ $item['num'] }}: {{ $item['name'] }}</li>

THT

file: config/app.jcon
{
    routes: {
        /benchmark/route/{pid}: /test-route.tht
    }
}
file: pages/test-route.tht
fun main {

    $pid = Input.route('pid')

    $items = []
    foreach range(1, 100) as $i {
        $item = {
            num: $i
            name: $pid ~ $i
        }
        $items #= $item
    }

    Output.sendHtml(pageHtml($pid, $items))
}

tem pageHtml($pid, $items) {

    <!doctype html>
    <html>
        <head>
            <title>Route Param Test</>
        </>
        <body>
            THT - Route Param: {{ $pid }}
            <ul>
            --- foreach $items as $item {
                {{ itemHtml($item) }}
            --- }
            </>
        </>
    </>
}

tem itemHtml($item) {
    <li>{{ $item.num }}: {{ $item.name }}</>
}