The flagship runnable Turbo demo. This example serves an interactive HTML
benchmark dashboard entirely from a single Turbo file. Visit
http://localhost:3000 and you get a styled dark-mode UI with five benchmark
cards (fibonacci, prime counter, bubble sort, sieve of Eratosthenes, and a
zero-cost language-info endpoint). Clicking any card — or Run All
Benchmarks — hits the matching /api/* route and prints the JSON response
and elapsed time.
If you want one example that proves Turbo can compile native code, serve a web UI, and expose JSON APIs today, this is the one to run first.
turbolang run examples/web-dashboard/main.tbThen:
- Open
http://localhost:3000in your browser - Click Run All Benchmarks
- Open
http://localhost:3000/api/infoin another tab to see a raw JSON route - Stop the server with
Ctrl+C
http_server(3000)+route(...)+http_listenfor serving HTML and JSON from the same process- A pure-Turbo HTML+CSS+JS builder (
build_css,build_js,build_card,build_html) using string concatenation and\{/\}escapes inside string literals to emit literal{/}for JS/CSS - Explicit response helpers:
respond_html,respond_json, andrespond_text - Recursive
fib, trial-divisionis_prime/count_primes, hashmap-basedsieve_count, andbubble_sortfor the benchmark workloads - Mutable arrays (
let mut arr = arr) with index assignment hashmap()+hashmap_set/hashmap_has+to_strfor the sieve
You can also hit the JSON endpoints directly:
curl http://localhost:3000/api/fib
curl http://localhost:3000/api/primes
curl http://localhost:3000/api/sort
curl http://localhost:3000/api/sieve
curl http://localhost:3000/api/infoThe server prints a banner and then blocks on http_listen:
==============================================
Turbo Interactive Benchmark Dashboard
http://localhost:3000
==============================================
Routes:
GET / - Dashboard UI
GET /api/fib - Fibonacci(35)
GET /api/primes - Count primes < 10,000
GET /api/sort - Bubble sort 500 integers
GET /api/sieve - Sieve of Eratosthenes < 100,000
GET /api/info - Language info
Dashboard ready. Press Ctrl+C to stop.
Sample response from GET /api/sieve:
{"benchmark": "sieve_eratosthenes", "limit": 100000, "prime_count": 9592}- The bubble sort over 500 reverse-sorted integers is intentionally slow. It's the slowest button on the dashboard by design.
- Inline CSS / JS uses
\{and\}because braces inside string literals would otherwise look like Turbo string interpolation. This is the current escape syntax — expect a cleaner option later. - Stop with
Ctrl+C.