2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file src/regex/perf-regex.c
23 * @brief Test how long it takes to create a automaton from a string regex.
24 * @author Bartlomiej Polot
29 #include "regex_internal_lib.h"
30 #include "regex_test_lib.h"
34 * Print information about the given node and its edges
37 * @param cls closure, unused.
38 * @param key hash for current state.
39 * @param proof proof for current state.
40 * @param accepting GNUNET_YES if this is an accepting state, GNUNET_NO if not.
41 * @param num_edges number of edges leaving current state.
42 * @param edges edges leaving current state.
46 const struct GNUNET_HashCode *key,
49 unsigned int num_edges,
50 const struct REGEX_BLOCK_Edge *edges)
54 printf("%s: %s, proof: `%s'\n",
56 accepting ? "ACCEPTING" : "",
58 for (i = 0; i < num_edges; i++)
61 GNUNET_h2s(&edges[i].destination));
66 * The main function of the regex performace test.
68 * Read a set of regex from a file, combine them and create a DFA from the
69 * resulting combined regex.
71 * @param argc number of arguments from the command line
72 * @param argv command line arguments
73 * @return 0 ok, 1 on error
76 main(int argc, char *const *argv)
78 struct REGEX_INTERNAL_Automaton* dfa;
83 unsigned int alphabet_size;
86 GNUNET_log_setup("perf-regex", "DEBUG", NULL);
90 "Usage: %s REGEX_FILE ALPHABET_SIZE COMPRESSION\n",
94 regexes = REGEX_TEST_read_from_file(argv[1]);
98 "Failed to read regexes from `%s'\n",
102 alphabet_size = atoi(argv[2]);
103 compression = atoi(argv[3]);
104 printf("********* PERF-REGEX *********'\n");
105 printf("Using:\n file '%s'\n Alphabet size %u\n compression %d\n",
106 argv[1], alphabet_size, compression);
108 buffer = REGEX_TEST_combine(regexes, alphabet_size);
109 GNUNET_asprintf(®ex, "GNUNET_REGEX_PROFILER_(%s)(0|1)*", buffer);
110 size = strlen(regex);
113 "Combined regex (%ld bytes):\n%s\n",
116 dfa = REGEX_INTERNAL_construct_dfa(regex, size, compression);
117 printf("********* ALL EDGES *********'\n");
118 REGEX_INTERNAL_iterate_all_edges(dfa, &print_edge, NULL);
119 printf("\n\n********* REACHABLE EDGES *********'\n");
120 REGEX_INTERNAL_iterate_reachable_edges(dfa, &print_edge, NULL);
121 REGEX_INTERNAL_automaton_destroy(dfa);
123 REGEX_TEST_free_from_file(regexes);
128 /* end of prof-regex.c */