MCPcopy Create free account
hub / github.com/coreboot/coreboot / benchmark

Function benchmark

util/cbfstool/cbfscomptool.c:28–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28static int benchmark(void)
29{
30 const int bufsize = 10*1024*1024;
31 char *data = malloc(bufsize);
32 if (!data) {
33 fprintf(stderr, "out of memory\n");
34 return 1;
35 }
36 char *compressed_data = malloc(bufsize);
37 if (!compressed_data) {
38 free(data);
39 fprintf(stderr, "out of memory\n");
40 return 1;
41 }
42 int i, l = strlen(usage_text) + 1;
43 for (i = 0; i + l < bufsize; i += l) {
44 memcpy(data + i, usage_text, l);
45 }
46 memset(data + i, 0, bufsize - i);
47 const struct typedesc_t *algo;
48 for (algo = &types_cbfs_compression[0]; algo->name != NULL; algo++) {
49 int outsize = bufsize;
50 printf("measuring '%s'\n", algo->name);
51 comp_func_ptr comp = compression_function(algo->type);
52 if (comp == NULL) {
53 printf("no handler associated with algorithm\n");
54 free(data);
55 free(compressed_data);
56 return 1;
57 }
58
59 struct timespec t_s, t_e;
60 clock_gettime(CLOCK_MONOTONIC, &t_s);
61
62 if (comp(data, bufsize, compressed_data, &outsize)) {
63 printf("compression failed");
64 return 1;
65 }
66
67 clock_gettime(CLOCK_MONOTONIC, &t_e);
68 printf("compressing %d bytes to %d took %ld seconds\n",
69 bufsize, outsize,
70 (long)(t_e.tv_sec - t_s.tv_sec));
71 }
72 free(data);
73 free(compressed_data);
74 return 0;
75}
76
77static int compress(char *infile, char *outfile, char *algoname,
78 int write_header)

Callers 1

mainFunction · 0.85

Calls 8

fprintfFunction · 0.85
strlenFunction · 0.85
printfFunction · 0.85
compression_functionFunction · 0.85
mallocFunction · 0.50
freeFunction · 0.50
memcpyFunction · 0.50
memsetFunction · 0.50

Tested by

no test coverage detected