#include #include #include #define MEM_SIZE 100000000 #define REPEATS 3 #define ALIGN_SIZE sizeof(long) size_t sizes[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 100, 1000, 10000, 100000, 1000000}; int main() { int is; char * data = (char *)malloc(MEM_SIZE + ALIGN_SIZE); memset(data, ' ', MEM_SIZE + ALIGN_SIZE); printf(" size off count time(ms) MB/s\n"); for (is = 0; is < sizeof(sizes) / sizeof(sizes[0]); ++is) { size_t size = sizes[is]; size_t asize = (size + ALIGN_SIZE - 1) / ALIGN_SIZE * ALIGN_SIZE; size_t off; printf("\n"); for (off = 0; off < ALIGN_SIZE; ++off) { size_t up = MEM_SIZE + off - size; int i, j, c; double t; struct timespec ts, te; clock_gettime(CLOCK_MONOTONIC, &ts); for (j = 0; j < REPEATS; ++j) { for (i = off; i <= up; i += asize) { PyObject * v = PyUnicode_DecodeASCII(data + i, size, NULL); Py_XDECREF(v); } } clock_gettime(CLOCK_MONOTONIC, &te); t = ((te.tv_sec - ts.tv_sec) + (te.tv_nsec - ts.tv_nsec) / 1e9) / REPEATS; c = ((up - off) / asize + 1); printf("%7ld %2d %8d %-8.3g %-8.3g\n", (long)size, off, c, 1e6 * t / c, 1.0 * c * size / t / 1e6); } fflush(stdout); } return 0; }