← Commit list

c2921730a7

Daniel Stenberg
Daniel Stenberg
2026-09-02
SUCCESS Duration: 428s

Subject

perf/base64: split into separate encoding plus decoding tests

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

tests/perf/Makefile.inc+2 -1
@@ -43,7 +43,8 @@ CURLX_C = \
# All performance test programs
TESTS_C = \
- base64.c \
+ base64dec.c \
+ base64enc.c \
percent.c \
snprintf.c \
urlparser.c
tests/perf/README.md+15 -5
@@ -24,13 +24,23 @@ them: `./perf urlparser URLs.txt [loops]`
A test sample of 100K URLs can be found
[here](https://raw.githubusercontent.com/ada-url/url-various-datasets/refs/heads/main/top100/top100.txt)
-## `base64`
+## `base64enc`
-This test first base64 encodes a 256-byte buffer that has every different
-byte octet represented. It then decodes that string. Repeatedly in a loop the
-provided number of times: `./perf base64 [loops]`
+This test base64 encodes a 256-byte buffer that has every different byte octet
+represented. Repeatedly in a loop the provided number of times:
+
+ ./perf base64enc [loops]
+
+## `base64dec`
+
+This test base64 decodes a big encoded string. Repeatedly in a loop the
+provided number of times:
+
+ ./perf base64dec [loops]
## `snprintf`
This test repeatedly formats a representative string and measures the time per
-call: `./perf snprintf [loops]`
+call:
+
+ ./perf snprintf [loops]
tests/perf/base64dec.c+72 -0
@@ -0,0 +1,72 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+#include "first.h"
+
+/* this is 256 bytes using the octets 0-255, base64 encoded */
+#define BLOB64 \
+ "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMD" \
+ "EyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFi" \
+ "Y2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5" \
+ "SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TF" \
+ "xsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19v" \
+ "f4+fr7/P3+/w=="
+
+static int test_base64dec(int argc, const char **argv)
+{
+ struct curltime start;
+ struct curltime end;
+ timediff_t us;
+ long long hn;
+ curl_off_t loops = 10000000, loop;
+
+ if(argc > 1) {
+ const char *ptr = argv[1];
+ curl_off_t num;
+ if(!curlx_str_number(&ptr, &num, CURL_OFF_T_MAX) && !*ptr)
+ loops = num;
+ }
+
+ start = curlx_now();
+ for(loop = 0; loop < loops; loop++) {
+ unsigned char *recoded = NULL;
+ size_t reclen;
+ CURLcode result = curlx_base64_decode(BLOB64, &recoded, &reclen);
+ curlx_free(recoded);
+ if(result) {
+ curl_mfprintf(stderr, "unexpected coding error: %d\n", (int)result);
+ return 1;
+ }
+ }
+ end = curlx_now();
+ us = curlx_timediff_us(end, start); /* how many microseconds */
+ hn = loop ? us * 100000 / loops : 0; /* 100 times too big */
+ curl_mprintf("Loops: %" CURL_FORMAT_CURL_OFF_T "\n"
+ "Time: %lld usecs\n"
+ "Time/loop: %lld.%0lld ns\n",
+ loops,
+ (long long)us,
+ (long long)hn / 100,
+ (long long)hn % 100);
+ return 0;
+}
tests/perf/base64.c → tests/perf/base64enc.c+1 -8
@@ -23,7 +23,7 @@
***************************************************************************/
#include "first.h"
-static int test_base64(int argc, const char **argv)
+static int test_base64enc(int argc, const char **argv)
{
struct curltime start;
struct curltime end;
@@ -52,13 +52,6 @@ static int test_base64(int argc, const char **argv)
size_t enclen;
CURLcode result =
curlx_base64_encode(array, sizeof(array), &encoded, &enclen);
- if(!result) {
- unsigned char *recoded = NULL;
- size_t reclen;
- /* now decode it again */
- result = curlx_base64_decode(encoded, &recoded, &reclen);
- curlx_free(recoded);
- }
if(result) {
curl_mfprintf(stderr, "unexpected coding error: %d\n", (int)result);
return 1;