-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlower-obsolete.c
More file actions
79 lines (66 loc) · 1.47 KB
/
lower-obsolete.c
File metadata and controls
79 lines (66 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Benchmark versions of string-lower-casing function */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "clock.h"
#include "fcyc.h"
#define ABITS 18
#define ASIZE (1 << ABITS)
/* Keep track of a number of different combining programs */
#define MAX_BENCHMARKS 10
typedef void (*lower_t)(char *);
static char data[ASIZE];
static void setup(int len)
{
int i;
for (i = 0; i < len-1; i++)
data[i] = 'a' + i%26;
data[len-1] = '\0';
}
lower_t current_lf;
void run(int *junk) {
current_lf(data);
}
/* Perform test of combinition function */
static void run_test(lower_t lf, int len)
{
double time;
double tpe;
current_lf = lf;
setup(len);
current_lf(data);
time = fcyc(run, NULL) / mhz(0) * 1e-6;
tpe = time * 1e6 /(double) len;
/* print results */
printf("%d\t%f\t%f\n", len, time, tpe);
}
void quad_lower(char *s)
{
int i;
for (i = 0; i < strlen(s); i++)
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] -= ('A' - 'a');
}
void lin_lower(char *s)
{
int i;
int len = strlen(s);
for (i = 0; i < len; i++)
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] -= ('A' - 'a');
}
int main()
{
int size;
printf("Linear: \n");
printf("Length\tSeconds\tuSPE\n");
for (size = 1; size <= ABITS; size++) {
run_test(lin_lower, 1<<size);
}
printf("Quadratic:\n");
printf("Length\tSeconds\tuSPE\n");
for (size = 1; size <= ABITS; size++) {
run_test(quad_lower, 1<<size);
}
return 0;
}