Add std/png mimic benches

Wuffs' std/png and std/zlib implementations have not been optimized yet,
but even at this early stage, they are roughly on par with their
"mimics": equivalent production-quality C libraries (libpng and zlib).

On a mid-range x86_64 laptop:

wuffs_png_decode_19k_8bpp/clang9     95.8MB/s ± 0%
wuffs_png_decode_40k_24bpp/clang9     100MB/s ± 1%
wuffs_png_decode_77k_8bpp/clang9      359MB/s ± 0%
wuffs_png_decode_552k_32bpp/clang9    119MB/s ± 0%
wuffs_png_decode_4002k_24bpp/clang9   101MB/s ± 0%

wuffs_png_decode_19k_8bpp/gcc10      97.2MB/s ± 0%
wuffs_png_decode_40k_24bpp/gcc10      111MB/s ± 0%
wuffs_png_decode_77k_8bpp/gcc10       316MB/s ± 0%
wuffs_png_decode_552k_32bpp/gcc10     132MB/s ± 0%
wuffs_png_decode_4002k_24bpp/gcc10    116MB/s ± 0%

mimic_png_decode_19k_8bpp            58.1MB/s ± 0%
mimic_png_decode_40k_24bpp           73.3MB/s ± 0%
mimic_png_decode_77k_8bpp             177MB/s ± 0%
mimic_png_decode_552k_32bpp           147MB/s ± 0%
mimic_png_decode_4002k_24bpp          104MB/s ± 0%

wuffs_zlib_decode_10k/clang9   126MB/s ± 0%
wuffs_zlib_decode_100k/clang9  136MB/s ± 0%

wuffs_zlib_decode_10k/gcc10    131MB/s ± 0%
wuffs_zlib_decode_100k/gcc10   159MB/s ± 0%

mimic_zlib_decode_10k          133MB/s ± 0%
mimic_zlib_decode_100k         160MB/s ± 0%
This commit is contained in:
Nigel Tao committed 2020-12-28 15:52:46 +11:00
1 parent 5ad6238f34
commit 88616cc969
3 files changed
+330 -12

No files matched your search

+93
View File
@@ -79,6 +79,20 @@ wuffs_testlib__initialize_global_xxx_slices() {
});
}
uint8_t //
unhex(uint8_t b) {
if (('0' <= b) && (b <= '9')) {
return b - '0';
}
if (('A' <= b) && (b <= 'F')) {
return b + 10 - 'A';
}
if (('a' <= b) && (b <= 'f')) {
return b + 10 - 'a';
}
return 0;
}
char g_fail_msg[65536] = {0};
#define RETURN_FAIL(...) \
@@ -568,6 +582,72 @@ copy_to_io_buffer_from_pixel_buffer(wuffs_base__io_buffer* dst,
return NULL;
}
bool //
skip_read_file_patches(const char** path) {
const char* p = *path;
while (*p == '@') {
p++;
while (*p != ';') {
if (*p == '\x00') {
return false;
}
p++;
}
p++;
}
*path = p;
return true;
}
bool //
apply_read_file_patches(wuffs_base__io_buffer* dst,
const char* original_path,
size_t original_wi) {
const char* p = original_path;
while (*p == '@') {
p++;
uint64_t offset = 0;
while (*p != '=') {
if (*p == '\x00') {
return false;
}
offset = (offset << 4) | unhex(*p);
p++;
}
p++;
uint8_t before = 0;
while (*p != '=') {
if (*p == '\x00') {
return false;
}
before = (before << 4) | unhex(*p);
p++;
}
p++;
uint8_t after = 0;
while (*p != ';') {
if (*p == '\x00') {
return false;
}
after = (after << 4) | unhex(*p);
p++;
}
p++;
size_t i = original_wi + offset;
if ((i >= dst->meta.wi) || (dst->data.ptr[i] != before)) {
return false;
}
dst->data.ptr[i] = after;
}
return true;
}
// read_file loads path into dst.
//
// The path may be preceded by zero or more "@123=45=67;" sub-strings, which
// denote a one-byte patch at offset 0x123, changing the byte at that offset
// from 0x45 to 0x67.
const char* //
read_file(wuffs_base__io_buffer* dst, const char* path) {
if (!dst || !path) {
@@ -576,6 +656,14 @@ read_file(wuffs_base__io_buffer* dst, const char* path) {
if (dst->meta.closed) {
RETURN_FAIL("read_file: dst buffer closed for writes");
}
const char* original_path = path;
size_t original_wi = dst->meta.wi;
if (!skip_read_file_patches(&path)) {
RETURN_FAIL("read_file(\"%s\"): invalid \"@123=45=67;\" patch",
original_path);
}
FILE* f = fopen(path, "r");
if (!f) {
RETURN_FAIL("read_file(\"%s\"): %s (errno=%d)", path, strerror(errno),
@@ -618,6 +706,11 @@ read_file(wuffs_base__io_buffer* dst, const char* path) {
fclose(f);
dst->meta.pos = 0;
dst->meta.closed = true;
if (!apply_read_file_patches(dst, original_path, original_wi)) {
RETURN_FAIL("read_file(\"%s\"): invalid \"@123=45=67;\" patch",
original_path);
}
return NULL;
}