<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Performance on almost done</title><link>https://nietaki.com/tags/performance/</link><description>Recent content in Performance on almost done</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>hello@nietaki.com (nietaki)</managingEditor><webMaster>hello@nietaki.com (nietaki)</webMaster><lastBuildDate>Fri, 21 Apr 2023 13:00:00 +0000</lastBuildDate><atom:link href="https://nietaki.com/tags/performance/index.xml" rel="self" type="application/rss+xml"/><item><title>Elixir string operations seem slow (and why it's a good thing)</title><link>https://nietaki.com/2023/04/21/elixir-string-operations-seem-slow-and-why-its-a-good-thing/</link><pubDate>Fri, 21 Apr 2023 13:00:00 +0000</pubDate><author>hello@nietaki.com (nietaki)</author><guid>https://nietaki.com/2023/04/21/elixir-string-operations-seem-slow-and-why-its-a-good-thing/</guid><description>&lt;p&gt;I personally hate it when people post clickbait titles and take their sweet time getting to the point, so let&amp;rsquo;s do this first:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: Some Elixir string operations, most notably &lt;a href="https://hexdocs.pm/elixir/String.html#at/2" target="_blank" rel="noreferrer"&gt;&lt;code&gt;String.at/2&lt;/code&gt;&lt;/a&gt; work in &lt;a href="https://en.wikipedia.org/wiki/Time_complexity#Linear_time" target="_blank" rel="noreferrer"&gt;linear time&lt;/a&gt;,
as opposed to &lt;a href="https://en.wikipedia.org/wiki/Time_complexity#Linear_time" target="_blank" rel="noreferrer"&gt;constant time&lt;/a&gt;, like the intuition might suggest. This is because the &lt;code&gt;String&lt;/code&gt; module is UTF-8 aware.
UTF-8 encodes characters outside of ASCII with more than one byte, so in order to find the n-th character in a string you need to process it from the beginning, you can&amp;rsquo;t just use an offset in memory.&lt;/p&gt;</description></item></channel></rss>