<feed xmlns='http://www.w3.org/2005/Atom'>
<title>askama/testing/benches, branch main</title>
<subtitle>added poem support</subtitle>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/'/>
<entry>
<title>Generator: make `normalize_identifier` faster (#946)</title>
<updated>2024-01-12T19:41:46+00:00</updated>
<author>
<name>René Kijewski</name>
<email>Kijewski@users.noreply.github.com</email>
</author>
<published>2024-01-12T19:41:46+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=3cddb918897383402a58a5d74b49500571144056'/>
<id>3cddb918897383402a58a5d74b49500571144056</id>
<content type='text'>
`normalize_identifier` is called quite often in the generator, once for
every variable name or path element that is written.

This PR aims to speed up the function by

* using a per-length input string length replacement map
* binary searching the replacement map instead of a linear search

Diffent, but functionally equivalent implementations were compared:

```text
* linear search in one big map:      348.44 µs
* binary search in one big map:      334.46 µs
* linear search in a per-length map: 178.84 µs
* binary search in a per-length map: 154.54 µs
* perfect hashing:                   170.87 µs
```

The winner of this competition is "binary search in a per-length map".
It does not introduce new dependencies, but has the slight disadvantage
that it uses one instance of `unsafe` code. I deem this disadvantage
acceptable, though.

Nb. It was also tested if a variant that only stores the replaced string
would be faster. This "optimization" proved to be slower for all
implementations except "binary search in a per-length map", for which it
has the same runtime. Without a clear advantage to use the "optimized
version", I chose to use the more easy to read slice of tuples variant.

Obviously, for all measurements: YMMV.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
`normalize_identifier` is called quite often in the generator, once for
every variable name or path element that is written.

This PR aims to speed up the function by

* using a per-length input string length replacement map
* binary searching the replacement map instead of a linear search

Diffent, but functionally equivalent implementations were compared:

```text
* linear search in one big map:      348.44 µs
* binary search in one big map:      334.46 µs
* linear search in a per-length map: 178.84 µs
* binary search in a per-length map: 154.54 µs
* perfect hashing:                   170.87 µs
```

The winner of this competition is "binary search in a per-length map".
It does not introduce new dependencies, but has the slight disadvantage
that it uses one instance of `unsafe` code. I deem this disadvantage
acceptable, though.

Nb. It was also tested if a variant that only stores the replaced string
would be faster. This "optimization" proved to be slower for all
implementations except "binary search in a per-length map", for which it
has the same runtime. Without a clear advantage to use the "optimized
version", I chose to use the more easy to read slice of tuples variant.

Obviously, for all measurements: YMMV.</pre>
</div>
</content>
</entry>
<entry>
<title>Clean up clippy warnings</title>
<updated>2020-01-02T21:58:13+00:00</updated>
<author>
<name>Dirkjan Ochtman</name>
<email>dirkjan@ochtman.nl</email>
</author>
<published>2020-01-02T20:21:28+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=ea2034e8062f8db6b5ae74ca8aeab4e2ee08479f'/>
<id>ea2034e8062f8db6b5ae74ca8aeab4e2ee08479f</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Use 2018 edition idioms</title>
<updated>2018-12-08T20:43:20+00:00</updated>
<author>
<name>Dirkjan Ochtman</name>
<email>dirkjan@ochtman.nl</email>
</author>
<published>2018-12-07T14:52:26+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=5549f9a3cd94e3cd6700067b1c74194dadb58a0f'/>
<id>5549f9a3cd94e3cd6700067b1c74194dadb58a0f</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Move escaping benchmarks into askama_escape crate</title>
<updated>2018-11-14T15:18:19+00:00</updated>
<author>
<name>Dirkjan Ochtman</name>
<email>dirkjan@ochtman.nl</email>
</author>
<published>2018-11-14T14:57:22+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=e7fde0733b25b9e404743b1a49e06b12a0371cb5'/>
<id>e7fde0733b25b9e404743b1a49e06b12a0371cb5</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Add bench for escaping</title>
<updated>2018-11-05T20:03:31+00:00</updated>
<author>
<name>bott</name>
<email>mhpoin@gmail.com</email>
</author>
<published>2018-11-03T13:05:27+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=2721c44a20f3e3af5bb2facdbb77c64652f160a8'/>
<id>2721c44a20f3e3af5bb2facdbb77c64652f160a8</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Remove unused #[macro_use] attribute</title>
<updated>2018-11-04T21:10:09+00:00</updated>
<author>
<name>Dirkjan Ochtman</name>
<email>dirkjan@ochtman.nl</email>
</author>
<published>2018-11-04T21:10:09+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=efe621195e3e2459275e4985659c8b0158d0b880'/>
<id>efe621195e3e2459275e4985659c8b0158d0b880</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix formatting with cargo fmt</title>
<updated>2018-07-02T07:28:02+00:00</updated>
<author>
<name>Dirkjan Ochtman</name>
<email>dirkjan@ochtman.nl</email>
</author>
<published>2018-07-02T07:28:02+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=ec2e873d73a3f820fe301b682cb100d07f44994b'/>
<id>ec2e873d73a3f820fe301b682cb100d07f44994b</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Add benchmarks to the Askama repo</title>
<updated>2018-06-28T15:01:12+00:00</updated>
<author>
<name>Dirkjan Ochtman</name>
<email>dirkjan@ochtman.nl</email>
</author>
<published>2018-06-28T15:01:12+00:00</published>
<link rel='alternate' type='text/html' href='https://bunny.garden/forks/askama/commit/?id=970e3ecfbdf9e4e4c4faacdb87efa656e812398a'/>
<id>970e3ecfbdf9e4e4c4faacdb87efa656e812398a</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
