Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.0 KiB
47 lines
1.0 KiB
16 years ago
|
|
||
|
#include <stdbool.h>
|
||
|
#include <time.h>
|
||
|
#include <stdio.h>
|
||
16 years ago
|
#include <unistd.h>
|
||
|
#include <string.h>
|
||
16 years ago
|
|
||
|
static bool initialize();
|
||
|
static void cleanup();
|
||
|
static size_t run();
|
||
|
|
||
|
int main (int argc, char *argv[])
|
||
|
{
|
||
16 years ago
|
(void)argc;
|
||
|
|
||
|
/* Change cwd to where the binary is. */
|
||
|
char *lastslash = strrchr(argv[0], '/');
|
||
|
char *progname = argv[0];
|
||
|
if(lastslash) {
|
||
|
*lastslash = '\0';
|
||
|
chdir(argv[0]);
|
||
|
*lastslash = '/';
|
||
|
progname = lastslash + 3; /* "/b_" */
|
||
|
}
|
||
|
|
||
16 years ago
|
if(!initialize()) {
|
||
|
fprintf(stderr, "%s: failed to initialize\n", argv[0]);
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
size_t total_bytes = 0;
|
||
|
clock_t before = clock();
|
||
|
for(int i = 0; true; i++) {
|
||
|
if((i & 0xFF) == 0 && (clock() - before > CLOCKS_PER_SEC)) break;
|
||
|
size_t bytes = run();
|
||
|
if(bytes == 0) {
|
||
|
fprintf(stderr, "%s: failed.\n", argv[0]);
|
||
|
return 2;
|
||
|
}
|
||
|
total_bytes += bytes;
|
||
|
}
|
||
|
double elapsed = ((double)clock() - before) / CLOCKS_PER_SEC;
|
||
16 years ago
|
printf("%s:%d\n", progname, (int)(total_bytes / elapsed / (1 << 20)));
|
||
16 years ago
|
cleanup();
|
||
|
return 0;
|
||
|
}
|