GNUnet  0.10.x
Functions
perf-regex.c File Reference

Test how long it takes to create a automaton from a string regex. More...

#include <regex.h>
#include <time.h>
#include "platform.h"
#include "regex_internal_lib.h"
#include "regex_test_lib.h"
Include dependency graph for perf-regex.c:

Go to the source code of this file.

Functions

static void print_edge (void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges)
 Print information about the given node and its edges to stdout. More...
 
int main (int argc, char *const *argv)
 The main function of the regex performace test. More...
 

Detailed Description

Test how long it takes to create a automaton from a string regex.

Author
Bartlomiej Polot

Definition in file perf-regex.c.

Function Documentation

◆ print_edge()

static void print_edge ( void *  cls,
const struct GNUNET_HashCode key,
const char *  proof,
int  accepting,
unsigned int  num_edges,
const struct REGEX_BLOCK_Edge edges 
)
static

Print information about the given node and its edges to stdout.

Parameters
clsclosure, unused.
keyhash for current state.
proofproof for current state.
acceptingGNUNET_YES if this is an accepting state, GNUNET_NO if not.
num_edgesnumber of edges leaving current state.
edgesedges leaving current state.

Definition at line 45 of file perf-regex.c.

References GNUNET_h2s().

Referenced by main().

51 {
52  unsigned int i;
53 
54  printf("%s: %s, proof: `%s'\n",
55  GNUNET_h2s(key),
56  accepting ? "ACCEPTING" : "",
57  proof);
58  for (i = 0; i < num_edges; i++)
59  printf(" `%s': %s\n",
60  edges[i].label,
61  GNUNET_h2s(&edges[i].destination));
62 }
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static uint64_t proof
Definition: gnunet-scrypt.c:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function of the regex performace test.

Read a set of regex from a file, combine them and create a DFA from the resulting combined regex.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 76 of file perf-regex.c.

References GNUNET_asprintf(), GNUNET_free, GNUNET_log_setup(), print_edge(), REGEX_INTERNAL_Automaton::regex, REGEX_INTERNAL_automaton_destroy(), REGEX_INTERNAL_construct_dfa(), REGEX_INTERNAL_iterate_all_edges(), REGEX_INTERNAL_iterate_reachable_edges(), REGEX_TEST_combine(), REGEX_TEST_free_from_file(), REGEX_TEST_read_from_file(), and size.

77 {
78  struct REGEX_INTERNAL_Automaton* dfa;
79  char **regexes;
80  char *buffer;
81  char *regex;
82  int compression;
83  unsigned int alphabet_size;
84  long size;
85 
86  GNUNET_log_setup("perf-regex", "DEBUG", NULL);
87  if (4 != argc)
88  {
89  fprintf(stderr,
90  "Usage: %s REGEX_FILE ALPHABET_SIZE COMPRESSION\n",
91  argv[0]);
92  return 1;
93  }
94  regexes = REGEX_TEST_read_from_file(argv[1]);
95  if (NULL == regexes)
96  {
97  fprintf(stderr,
98  "Failed to read regexes from `%s'\n",
99  argv[1]);
100  return 2;
101  }
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);
107  fflush(stdout);
108  buffer = REGEX_TEST_combine(regexes, alphabet_size);
109  GNUNET_asprintf(&regex, "GNUNET_REGEX_PROFILER_(%s)(0|1)*", buffer);
110  size = strlen(regex);
111 
112  fprintf(stderr,
113  "Combined regex (%ld bytes):\n%s\n",
114  size,
115  regex);
116  dfa = REGEX_INTERNAL_construct_dfa(regex, size, compression);
117  printf("********* ALL EDGES *********'\n");
119  printf("\n\n********* REACHABLE EDGES *********'\n");
122  GNUNET_free(buffer);
123  REGEX_TEST_free_from_file(regexes);
124  GNUNET_free(regex);
125  return 0;
126 }
static void print_edge(void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges)
Print information about the given node and its edges to stdout.
Definition: perf-regex.c:45
Automaton representation.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
char * REGEX_TEST_combine(char *const regexes[], unsigned int alphabet_size)
Combine an array of regexes into a single prefix-shared regex.
static unsigned int size
Size of the "table".
Definition: peer.c:66
void REGEX_INTERNAL_automaton_destroy(struct REGEX_INTERNAL_Automaton *a)
Free the memory allocated by constructing the REGEX_INTERNAL_Automaton data structure.
void REGEX_INTERNAL_iterate_all_edges(struct REGEX_INTERNAL_Automaton *a, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls)
Iterate over all edges starting from start state of automaton &#39;a&#39;.
void REGEX_TEST_free_from_file(char **regexes)
Free all memory reserved for a set of regexes created by read_from_file.
struct REGEX_INTERNAL_Automaton * REGEX_INTERNAL_construct_dfa(const char *regex, const size_t len, unsigned int max_path_len)
Construct DFA for the given &#39;regex&#39; of length &#39;len&#39;.
char ** REGEX_TEST_read_from_file(const char *filename)
Read a set of regexes from a file, one per line and return them in an array suitable for REGEX_TEST_c...
void REGEX_INTERNAL_iterate_reachable_edges(struct REGEX_INTERNAL_Automaton *a, REGEX_INTERNAL_KeyIterator iterator, void *iterator_cls)
Iterate over all edges of automaton &#39;a&#39; that are reachable from a state with a proof of at least GNUN...
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: