From: Alexander Kuzmenkov <a.kuzmenkov@postgrespro.ru>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Subject: Re: Performance improvements for src/port/snprintf.c
Date: Fri, 7 Sep 2018 21:53:27 +0300
Message-ID: <f5dd41da-911c-fd97-1b78-e0f8c0141897@postgrespro.ru> (raw)
In-Reply-To: <2238.1534716465@sss.pgh.pa.us>
References: <11787.1534530779@sss.pgh.pa.us>
<2238.1534716465@sss.pgh.pa.us>
I benchmarked this, using your testbed and comparing to libc sprintf
(Ubuntu GLIBC 2.27-0ubuntu3) and another implementation I know [1], all
compiled with gcc 5.4.0 with -O2. I used bigger decimals in one of the
formats, but otherwise they are the same as yours. Here is the table of
conversion time relative to libc:
format pg stb
("%2$.*3$f %1$d\n", 42, 123.456, 2) 1.03 -
("%.*g", 15, 123.456) 1.08 0.31
("%10d", 15) 0.63 0.52
("%s", "012345678900123456789001234 2.06 6.20
("%d 012345678900123456789001234567 2.03 1.81
("%1$d 0123456789001234567890012345 1.34 -
("%d %d", 845879348, 994502893) 1.97 0.59
Surprisingly, our implementation is twice faster than libc on "%10d".
Stb is faster than we are with floats, but it uses its own algorithm for
that. It is also faster with decimals, probably because it uses a
two-digit lookup table, not one-digit like we do. Unfortunately it
doesn't support dollars.
1. https://github.com/nothings/stb/blob/master/stb_sprintf.h
--
Alexander Kuzmenkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: a.kuzmenkov@postgrespro.ru, tgl@sss.pgh.pa.us, pgsql-hackers@lists.postgresql.org
Subject: Re: Performance improvements for src/port/snprintf.c
In-Reply-To: <f5dd41da-911c-fd97-1b78-e0f8c0141897@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox