diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-29 13:23:31 +0100 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-29 13:42:37 +0100 |
| commit | b70ee41c5c3aebd36190aa1508368a9bc287fb21 (patch) | |
| tree | be51d863129204f269c83a5d0b59f62839c80d3a /util/libreboot-utils/lib | |
| parent | cec3de5c9eacb92e45fcd4ff88998d9b35e38663 (diff) | |
hexdump performance test, part 1
spoiler alert: it's slow as molasses
part 2 will be presented at a later date
(yes, please don't fill 8GB of memory with
random data and hexdump it)
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/libreboot-utils/lib')
| -rw-r--r-- | util/libreboot-utils/lib/num.c | 18 | ||||
| -rw-r--r-- | util/libreboot-utils/lib/string.c | 5 |
2 files changed, 20 insertions, 3 deletions
diff --git a/util/libreboot-utils/lib/num.c b/util/libreboot-utils/lib/num.c index e4d0ce6b..bf4afaef 100644 --- a/util/libreboot-utils/lib/num.c +++ b/util/libreboot-utils/lib/num.c @@ -50,6 +50,22 @@ hextonum(char ch_s) } /* basically hexdump -C */ +/* + TODO: optimise this + write a full util for hexdump + how to optimise: + don't call print tens of thousands of times! + convert the numbers manually, and cache everything + in a BUFSIZ sized buffer, with everything properly + aligned. i worked out that i could fit 79 rows + in a 8KB buffer (1264 bytes of numbers represented + as strings in hex) + this depends on the OS, and would be calculated at + runtime. + then: + don't use printf. just write it to stdout (basically + a simple cat implementation) +*/ void spew_hex(const void *data, size_t len) { @@ -64,7 +80,7 @@ spew_hex(const void *data, size_t len) for (i = 0; i < len; i += 16) { - printf("%08zx ", i); + printf("%0*zx ", sizeof(size_t) * 2, i); for (j = 0; j < 16; j++) { diff --git a/util/libreboot-utils/lib/string.c b/util/libreboot-utils/lib/string.c index 9adbb120..39b31cb0 100644 --- a/util/libreboot-utils/lib/string.c +++ b/util/libreboot-utils/lib/string.c @@ -179,7 +179,6 @@ scatn(ssize_t sc, const char **sv, size_t max, char **rval) { int saved_errno = errno; - char *final = NULL; char *rcur = NULL; char *rtmp = NULL; @@ -192,7 +191,9 @@ scatn(ssize_t sc, const char **sv, for (i = 0; i < sc; i++) { - if (i == 0) { + if (if_err(sv[i] == NULL, EFAULT)) + goto err; + else if (i == 0) { if (sdup(sv[0], max, &final) < 0) goto err; continue; |
