Deleted Added
full compact
timings.c (171195) timings.c (171525)
1/*-
2 * Copyright (c) 2007 Sean C. Farley <scf@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
1/*-
2 * Copyright (c) 2007 Sean C. Farley <scf@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26#include <sys/types.h>
26#include <sys/time.h>
27#include <sys/time.h>
28#include <sys/resource.h>
27#include <err.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <unistd.h>
32
33
34#include <sys/cdefs.h>
29#include <err.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <unistd.h>
34
35
36#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/tools/regression/environ/timings.c 171195 2007-07-04 00:00:41Z scf $");
37__FBSDID("$FreeBSD: head/tools/regression/environ/timings.c 171525 2007-07-20 23:30:13Z scf $");
36
37
38const char value1[] = "Large ------------------ value";
39const char value2[] = "Small -- value";
40char nameValuePair[] = "less=more";
41const char name[] = "PATH";
42const char name2[] = "SHELL";
43const int MaxIterations = 1000000;

--- 15 unchanged lines hidden (view full) ---

59 (double)(endTime->tv_usec - startTime->tv_usec) / 1000000));
60}
61
62
63int
64main(int argc, char **argv)
65{
66 int iterations;
38
39
40const char value1[] = "Large ------------------ value";
41const char value2[] = "Small -- value";
42char nameValuePair[] = "less=more";
43const char name[] = "PATH";
44const char name2[] = "SHELL";
45const int MaxIterations = 1000000;

--- 15 unchanged lines hidden (view full) ---

61 (double)(endTime->tv_usec - startTime->tv_usec) / 1000000));
62}
63
64
65int
66main(int argc, char **argv)
67{
68 int iterations;
67 struct timeval endTime;
68 struct timeval startTime;
69 struct rusage endUsage;
70 struct rusage startUsage;
69
70 /*
71 * getenv() on the existing environment.
72 */
71
72 /*
73 * getenv() on the existing environment.
74 */
73 gettimeofday(&startTime, NULL);
75 getrusage(RUSAGE_SELF, &startUsage);
74
75 /* Iterate over setting variable. */
76 for (iterations = 0; iterations < MaxIterations; iterations++)
77 if (getenv(name) == NULL)
78 err(EXIT_FAILURE, "getenv(name)");
79
76
77 /* Iterate over setting variable. */
78 for (iterations = 0; iterations < MaxIterations; iterations++)
79 if (getenv(name) == NULL)
80 err(EXIT_FAILURE, "getenv(name)");
81
80 gettimeofday(&endTime, NULL);
82 getrusage(RUSAGE_SELF, &endUsage);
81
83
82 report_time("getenv(name)", &startTime, &endTime);
84 report_time("getenv(name)", &startUsage.ru_utime, &endUsage.ru_utime);
83
84
85 /*
86 * setenv() a variable with a large value.
87 */
85
86
87 /*
88 * setenv() a variable with a large value.
89 */
88 gettimeofday(&startTime, NULL);
90 getrusage(RUSAGE_SELF, &startUsage);
89
90 /* Iterate over setting variable. */
91 for (iterations = 0; iterations < MaxIterations; iterations++)
92 if (setenv(name, value1, 1) == -1)
93 err(EXIT_FAILURE, "setenv(name, value1, 1)");
94
91
92 /* Iterate over setting variable. */
93 for (iterations = 0; iterations < MaxIterations; iterations++)
94 if (setenv(name, value1, 1) == -1)
95 err(EXIT_FAILURE, "setenv(name, value1, 1)");
96
95 gettimeofday(&endTime, NULL);
97 getrusage(RUSAGE_SELF, &endUsage);
96
98
97 report_time("setenv(name, value1, 1)", &startTime, &endTime);
99 report_time("setenv(name, value1, 1)", &startUsage.ru_utime,
100 &endUsage.ru_utime);
98
99
100 /*
101 * getenv() the new variable on the new environment.
102 */
101
102
103 /*
104 * getenv() the new variable on the new environment.
105 */
103 gettimeofday(&startTime, NULL);
106 getrusage(RUSAGE_SELF, &startUsage);
104
105 /* Iterate over setting variable. */
106 for (iterations = 0; iterations < MaxIterations; iterations++)
107 /* Set large value to variable. */
108 if (getenv(name) == NULL)
109 err(EXIT_FAILURE, "getenv(name)");
110
107
108 /* Iterate over setting variable. */
109 for (iterations = 0; iterations < MaxIterations; iterations++)
110 /* Set large value to variable. */
111 if (getenv(name) == NULL)
112 err(EXIT_FAILURE, "getenv(name)");
113
111 gettimeofday(&endTime, NULL);
114 getrusage(RUSAGE_SELF, &endUsage);
112
115
113 report_time("getenv(name)", &startTime, &endTime);
116 report_time("getenv(name)", &startUsage.ru_utime, &endUsage.ru_utime);
114
115
116 /*
117 * getenv() a different variable on the new environment.
118 */
117
118
119 /*
120 * getenv() a different variable on the new environment.
121 */
119 gettimeofday(&startTime, NULL);
122 getrusage(RUSAGE_SELF, &startUsage);
120
121 /* Iterate over setting variable. */
122 for (iterations = 0; iterations < MaxIterations; iterations++)
123 /* Set large value to variable. */
124 if (getenv(name2) == NULL)
125 err(EXIT_FAILURE, "getenv(name2)");
126
123
124 /* Iterate over setting variable. */
125 for (iterations = 0; iterations < MaxIterations; iterations++)
126 /* Set large value to variable. */
127 if (getenv(name2) == NULL)
128 err(EXIT_FAILURE, "getenv(name2)");
129
127 gettimeofday(&endTime, NULL);
130 getrusage(RUSAGE_SELF, &endUsage);
128
131
129 report_time("getenv(name2)", &startTime, &endTime);
132 report_time("getenv(name2)", &startUsage.ru_utime, &endUsage.ru_utime);
130
131
132 /*
133 * setenv() a variable with a small value.
134 */
133
134
135 /*
136 * setenv() a variable with a small value.
137 */
135 gettimeofday(&startTime, NULL);
138 getrusage(RUSAGE_SELF, &startUsage);
136
137 /* Iterate over setting variable. */
138 for (iterations = 0; iterations < MaxIterations; iterations++)
139 if (setenv(name, value2, 1) == -1)
140 err(EXIT_FAILURE, "setenv(name, value2, 1)");
141
139
140 /* Iterate over setting variable. */
141 for (iterations = 0; iterations < MaxIterations; iterations++)
142 if (setenv(name, value2, 1) == -1)
143 err(EXIT_FAILURE, "setenv(name, value2, 1)");
144
142 gettimeofday(&endTime, NULL);
145 getrusage(RUSAGE_SELF, &endUsage);
143
146
144 report_time("setenv(name, value2, 1)", &startTime, &endTime);
147 report_time("setenv(name, value2, 1)", &startUsage.ru_utime,
148 &endUsage.ru_utime);
145
146
147 /*
148 * getenv() a different variable on the new environment.
149 */
149
150
151 /*
152 * getenv() a different variable on the new environment.
153 */
150 gettimeofday(&startTime, NULL);
154 getrusage(RUSAGE_SELF, &startUsage);
151
152 /* Iterate over setting variable. */
153 for (iterations = 0; iterations < MaxIterations; iterations++)
154 /* Set large value to variable. */
155 if (getenv(name2) == NULL)
156 err(EXIT_FAILURE, "getenv(name)");
157
155
156 /* Iterate over setting variable. */
157 for (iterations = 0; iterations < MaxIterations; iterations++)
158 /* Set large value to variable. */
159 if (getenv(name2) == NULL)
160 err(EXIT_FAILURE, "getenv(name)");
161
158 gettimeofday(&endTime, NULL);
162 getrusage(RUSAGE_SELF, &endUsage);
159
163
160 report_time("getenv(name)", &startTime, &endTime);
164 report_time("getenv(name)", &startUsage.ru_utime, &endUsage.ru_utime);
161
162
163 /*
164 * getenv() a different variable on the new environment.
165 */
165
166
167 /*
168 * getenv() a different variable on the new environment.
169 */
166 gettimeofday(&startTime, NULL);
170 getrusage(RUSAGE_SELF, &startUsage);
167
168 /* Iterate over setting variable. */
169 for (iterations = 0; iterations < MaxIterations; iterations++)
170 /* Set large value to variable. */
171 if (getenv(name2) == NULL)
172 err(EXIT_FAILURE, "getenv(name2)");
173
171
172 /* Iterate over setting variable. */
173 for (iterations = 0; iterations < MaxIterations; iterations++)
174 /* Set large value to variable. */
175 if (getenv(name2) == NULL)
176 err(EXIT_FAILURE, "getenv(name2)");
177
174 gettimeofday(&endTime, NULL);
178 getrusage(RUSAGE_SELF, &endUsage);
175
179
176 report_time("getenv(name2)", &startTime, &endTime);
180 report_time("getenv(name2)", &startUsage.ru_utime, &endUsage.ru_utime);
177
178
179 /*
180 * putenv() a variable with a small value.
181 */
181
182
183 /*
184 * putenv() a variable with a small value.
185 */
182 gettimeofday(&startTime, NULL);
186 getrusage(RUSAGE_SELF, &startUsage);
183
184 /* Iterate over setting variable. */
185 for (iterations = 0; iterations < MaxIterations; iterations++)
186 if (putenv(nameValuePair) == -1)
187 err(EXIT_FAILURE, "putenv(nameValuePair)");
188
187
188 /* Iterate over setting variable. */
189 for (iterations = 0; iterations < MaxIterations; iterations++)
190 if (putenv(nameValuePair) == -1)
191 err(EXIT_FAILURE, "putenv(nameValuePair)");
192
189 gettimeofday(&endTime, NULL);
193 getrusage(RUSAGE_SELF, &endUsage);
190
194
191 report_time("putenv(nameValuePair)", &startTime, &endTime);
195 report_time("putenv(nameValuePair)", &startUsage.ru_utime,
196 &endUsage.ru_utime);
192
193
194 exit(EXIT_SUCCESS);
195}
197
198
199 exit(EXIT_SUCCESS);
200}