source: tests/zombies/string-perf/make-corpus.cfa @ fefd77a

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since fefd77a was 01db301, checked in by Michael Brooks <mlbrooks@…>, 2 years ago

Baseline string performance experiment

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <stdlib.hfa>
2#include <math.h>
3#include <limits.h>
4#include <unistd.h>
5
6// generate random draws from a geometric distribution of the given mean
7// https://math.stackexchange.com/questions/485448/prove-the-way-to-generate-geometrically-distributed-random-numbers
8static double denom;
9static void initialize(int mean) {
10    srand(getpid());
11    double p = 1.0 / (double) mean;
12    denom = log(1-p);
13}
14static int nextGeoRand() {
15    // ret = ⌊ln(U)/ln(1−p)⌋ where U ~ U(0, 1)
16    double U = (double)rand() / (double)INT_MAX;
17    return 1 + (int) (log(U) / denom);
18}
19
20// write a randomly generated alphabetic string whose length is drawn from above distribution
21static void emit1() {
22    int lim = nextGeoRand();
23    // printf("==%d\n", lim);
24    for (i; lim) {
25        char emit = 'a' + (rand() % ('z'-'a'));
26        printf("%c", emit);
27    }
28    printf("\n");
29}
30
31// usage: ./make-corpus toGen mean
32int main(int argc, char ** argv) {
33    assert(argc == 3);
34
35    int toGen = atoi(argv[1]);
36    assert(toGen > 0);
37    assert(toGen < 1000000);
38
39    int mean = atoi(argv[2]);
40    assert(mean > 0);
41    assert(mean < 1000);
42
43    initialize(mean);
44    for( i; toGen ) {
45        emit1();
46    }
47}
Note: See TracBrowser for help on using the repository browser.