Skip to content

Instantly share code, notes, and snippets.

View llllllllll's full-sized avatar

Joe Jevnik llllllllll

View GitHub Profile
from collections import UserString
class ResolvedDocString(UserString):
__class__ = str
class DeferDocString(UserString):
def __init__(self, f):
self._f = f
#include <cstdlib>
#include <compare>
#include <ranges>
namespace jj {
class iota : public std::ranges::view_base {
public:
iota(long start, long end) : m_start(start), m_end(end) {}
iota(long end) : iota(0, end) {}
iota() : iota(0, 0) {}

Comments on optimizations around string concatenation.

Note: The code links are to CPython 3.8.5, the most recent release when this was written.

I was recently asked about a performance optimization in CPython around using += and + for string objects. As some people may already know, if you use += or + a string, it can sometimes be just as fast as ''.join. The question was to explain when that optimization couldn't be performed.

We will be going through the following example scenarios:

@llllllllll
llllllllll / notes.rst
Last active July 23, 2021 05:41
msgspec notes

Initial Observations

The provided benchmark script is using Python's timeit module for benchmarking. I noticed that I was getting very different results between runs even with the same compiler, so I first switched to pyperf to attempt to get more stable results.

I am not sure if there is a Python API for pyperf, so I started by writing a small bash wrapper for benchmark: