Last active
November 17, 2023 15:55
-
-
Save bagder/8efdcaf1244970887ba84bcf734637ba to your computer and use it in GitHub Desktop.
measure ada URL parsing the same way speedparse does
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 <sys/stat.h> | |
#include <sys/time.h> | |
#include "ada.cpp" | |
#include "ada.h" | |
#include <iostream> | |
#define FILENAME "URLs" | |
void *mem; | |
char **urls; | |
size_t url_num; | |
size_t url_alloc; | |
static void load_urls() | |
{ | |
struct stat st; | |
size_t memsize; | |
size_t left; | |
FILE *fp; | |
char *ptr; | |
stat(FILENAME, &st); | |
memsize = st.st_size; | |
mem = malloc(memsize + 1); | |
fp = fopen(FILENAME, "rb"); | |
fread(mem, memsize, 1, fp); | |
for(ptr = (char *)mem, left = memsize; left; ) { | |
char *nl; | |
if(url_alloc == url_num) { | |
if(!url_alloc) { | |
url_alloc = 10000; | |
} | |
url_alloc *= 2; | |
urls = (char **)realloc(urls, url_alloc * sizeof(char *)); | |
} | |
urls[url_num++] = ptr; | |
nl = (char *)memchr(ptr, '\n', left); | |
if(!nl) | |
break; | |
*nl++ = 0; | |
left -= nl - ptr; | |
ptr = nl; | |
} | |
printf("Loaded %u URLs from %s\n", url_num, FILENAME); | |
} | |
#define END_OF_LIST 0xffffff | |
int main(int argc, char **argv) | |
{ | |
int l, o, u; | |
int count = 0; | |
struct timeval start; | |
struct timeval end; | |
time_t diff; | |
long us; | |
int laps = 100; | |
if(argc > 1) | |
laps = atoi(argv[1]); | |
load_urls(); | |
gettimeofday(&start, NULL); | |
for(l = 0; l < laps; l++) { | |
for(u = 0; u < url_num; u++) { | |
ada::result<ada::url_aggregator> url = ada::parse<ada::url_aggregator>(urls[u]); | |
// auto url = ada::parse<ada::url>(urls[u]); | |
count++; | |
} | |
} | |
gettimeofday(&end, NULL); | |
diff = end.tv_sec-start.tv_sec; | |
us = diff * 1000000 + end.tv_usec-start.tv_usec; | |
printf("%d URLs in %.5f secs, %.1f ns/URL, %.3f URLs/sec\n", | |
count, (double)us/1000000.0, (double)us*1000/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