#include #include #include #include #include #include #include #include #include #include #define SIZE (1 * 1024 * 1024 * 1024) #define PAGE_SIZE 4096 int64_t current_time_ms() { struct timeval time; gettimeofday(&time, NULL); int64_t s1 = (int64_t)(time.tv_sec) * 1000; int64_t s2 = (time.tv_usec / 1000); return s1 + s2; } int main(int argc, char* argv[]) { void * buf; char * ptr; size_t size = SIZE, step = PAGE_SIZE; int64_t start, cost; buf = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); if (buf == MAP_FAILED) { printf("mmap failed\n"); } start = current_time_ms(); for(size_t i = 0; i < size; i += step ) { ptr = (char *)(buf + i); *ptr = 'a'; } cost = current_time_ms() - start; printf("cost:%" PRId64 " ms\n", cost); munmap(buf, size); return 0; }