<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Lisp on Benjamin Geer</title>
    <link>https://benjamingeer.eu/en/topics/lisp/</link>
    <description>Recent content in Lisp on Benjamin Geer</description>
    <generator>Hugo</generator>
    <language>en-GB</language>
    <lastBuildDate>Tue, 10 Mar 2026 13:49:30 +0100</lastBuildDate>
    <atom:link href="https://benjamingeer.eu/en/topics/lisp/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Comparing the performance of SQL queries</title>
      <link>https://benjamingeer.eu/en/post/sqlstopwatch/</link>
      <pubDate>Thu, 29 Jan 2026 18:25:18 +0100</pubDate>
      <guid>https://benjamingeer.eu/en/post/sqlstopwatch/</guid>
      <description>&lt;p&gt;I wrote a little Rust program,&#xA;&lt;a href=&#34;https://codeberg.org/benjamingeer/sqlstopwatch&#34; target=&#34;_blank&#34;&gt;sqlstopwatch&lt;/a&gt;, to compare the&#xA;performance of different &lt;a href=&#34;https://en.wikipedia.org/wiki/SQL&#34; target=&#34;_blank&#34;&gt;SQL&lt;/a&gt; queries. I&#xA;was inspired by the article &lt;a href=&#34;https://www.jooq.org/benchmark&#34; target=&#34;_blank&#34;&gt;Benchmarking SQL&lt;/a&gt;&#xA;published by the jOOQ project, where they write the test code in SQL. I wanted&#xA;something similar, but with a few additional requirements:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A command-line program with a simple&#xA;&lt;a href=&#34;https://en.wikipedia.org/wiki/Text-based_user_interface&#34; target=&#34;_blank&#34;&gt;TUI&lt;/a&gt; showing a&#xA;progress bar.&lt;/li&gt;&#xA;&lt;li&gt;The program should support &lt;a href=&#34;https://www.postgresql.org&#34; target=&#34;_blank&#34;&gt;PostgreSQL&lt;/a&gt;,&#xA;&lt;a href=&#34;https://www.mysql.com&#34; target=&#34;_blank&#34;&gt;MySQL&lt;/a&gt;, and &lt;a href=&#34;https://sqlite.org&#34; target=&#34;_blank&#34;&gt;SQLite&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;It should read the SQL queries and test parameters from a configuration file&#xA;specified on the command line.&lt;/li&gt;&#xA;&lt;li&gt;It should print the results as a table in the terminal or save them as a CSV&#xA;file that I can use to generate a chart.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The TUI was easy to make with &lt;a href=&#34;https://ratatui.rs&#34; target=&#34;_blank&#34;&gt;Ratatui&lt;/a&gt;. To interact with&#xA;the database, I used the async database library&#xA;&lt;a href=&#34;https://crates.io/crates/sqlx&#34; target=&#34;_blank&#34;&gt;sqlx&lt;/a&gt;, which provides a bundled SQLite&#xA;library.&lt;/p&gt;&#xA;&lt;p&gt;I considered using &lt;a href=&#34;https://toml.io&#34; target=&#34;_blank&#34;&gt;TOML&lt;/a&gt; for the config file, but the file&#xA;has to specify the database credentials. In testing environments, credentials&#xA;may have to be loaded from environment variables or from files on a mounted file&#xA;system, but TOML doesn&amp;rsquo;t support carrying out those sorts of operations.&#xA;Moreover, you might want to generate a number of similar queries and compare&#xA;them, as I did in &lt;a href=&#34;https://benjamingeer.eu/en/post/bref&#34;&gt;this database optimisation project&lt;/a&gt;.&#xA;Therefore, it&amp;rsquo;s better if the config file is a program in a scripting language.&#xA;My &lt;a href=&#34;https://benjamingeer.eu/en/post/organiclox&#34;&gt;exercise in writing an interpreter for a scripting&#xA;language&lt;/a&gt; had given me a new appreciation for the&#xA;&lt;a href=&#34;https://www.lua.org&#34; target=&#34;_blank&#34;&gt;Lua&lt;/a&gt; virtual machine. So the config file is a Lua&#xA;script, which I find more convenient to write in&#xA;&lt;a href=&#34;https://fennel-lang.org&#34; target=&#34;_blank&#34;&gt;Fennel&lt;/a&gt;, a Lisp dialect that compiles to Lua. Thanks&#xA;to the &lt;a href=&#34;https://crates.io/crates/mlua&#34; target=&#34;_blank&#34;&gt;mlua&lt;/a&gt; library, it was very easy to&#xA;embed a Lua interpreter in the program, and to use &lt;a href=&#34;https://serde.rs&#34; target=&#34;_blank&#34;&gt;Serde&lt;/a&gt;&#xA;to convert Lua tables into Rust &lt;code&gt;struct&lt;/code&gt;s.&lt;/p&gt;&#xA;</description>
    </item>
  </channel>
</rss>
