Created
January 31, 2023 09:17
-
-
Save bagder/d984079fca82524ed64e69dcaa429644 to your computer and use it in GitHub Desktop.
curl URL decode performance tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************************** | |
* _ _ ____ _ | |
* 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <curl/curl.h> | |
#define BLOCKSIZE 1000000 | |
char block[BLOCKSIZE]; | |
int main(int argc, char **argv) | |
{ | |
struct timeval start; | |
struct timeval end; | |
time_t diff; | |
long us; | |
int laps = 10000; | |
char *encoded; | |
size_t encodedlen; | |
int i, l; | |
int count = 0; | |
/* fill the block */ | |
for(i=0; i<BLOCKSIZE; i++) | |
block[i] = i&255; | |
/* URL encode */ | |
encoded = curl_easy_escape(NULL, block, BLOCKSIZE); | |
if(!encoded) | |
return 2; | |
encodedlen = strlen(encoded); | |
if(argc > 1) | |
laps = atoi(argv[1]); | |
gettimeofday(&start, NULL); | |
for(l = 0; l < laps; l++) { | |
int olen; | |
char *decode = curl_easy_unescape(NULL, encoded, encodedlen, &olen); | |
curl_free(decode); | |
count++; | |
} | |
gettimeofday(&end, NULL); | |
diff = end.tv_sec-start.tv_sec; | |
us = diff * 1000000 + end.tv_usec-start.tv_usec; | |
printf("%d URL decodes in %.5f secs, %.3f us/decode, %.3f decodes/sec\n", | |
count, (double)us/1000000.0, (double)us/count, count / (us/1000000.0)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment