static int do_memcpy(int iters, int sz) {
    struct timeval tv1;
    struct timeval tv2;
    int i, j;

    uint8_t *a = malloc(sz);
    if (!a) return -1;
    uint8_t *b = malloc(sz);
    if (!b) return -1;
    int c = 1000000000/sz;

    for (i = 0; iters == -1 || i < iters; i++) {
        gettimeofday(&tv1, NULL);
        for (j = 0; j < c; j++)
            memcpy(b, a, sz);

        gettimeofday(&tv2, NULL);

        tv_sub(&tv2, &tv1);

        printf("memcpy %dx%d bytes took %ld.%06ld seconds (%f MB/s)\n",
                c, sz, tv2.tv_sec, tv2.tv_usec, mb_sec(c*sz, &tv2));
    }
    return 0;
}
static int do_memread(int iters, int sz) {
    struct timeval tv1;
    struct timeval tv2;
    int i, j, k;

    int *b = malloc(sz);
    if (!b) return -1;
    int c = 1000000000/sz;

    for (i = 0; iters == -1 || i < iters; i++) {
        gettimeofday(&tv1, NULL);
        for (j = 0; j < c; j++)
            for (k = 0; k < sz/4; k++)
                foo = b[k];

        gettimeofday(&tv2, NULL);

        tv_sub(&tv2, &tv1);

        printf("read %dx%d bytes took %ld.%06ld seconds (%f MB/s)\n",
                c, sz, tv2.tv_sec, tv2.tv_usec, mb_sec(c*sz, &tv2));
    }
    return 0;
}
Beispiel #3
0
static int do_memset(int sz) {
    struct timeval tv1;
    struct timeval tv2;
    int i;

    uint8_t *b = malloc(sz);
    if (!b) return -1;
    int c = 1000000000/sz;

    while (1) {
        gettimeofday(&tv1, NULL);
        for (i = 0; i < c; i++)
            memset(b, 0, sz);

        gettimeofday(&tv2, NULL);

        tv_sub(&tv2, &tv1);

        printf("memset %dx%d bytes took %ld.%06ld seconds (%f MB/s)\n", c, sz, tv2.tv_sec, tv2.tv_usec, mb_sec(c*sz, &tv2));
    }
    return 0;
}