Last active
August 29, 2015 14:24
-
-
Save xudifsd/d755934aad6fc9ca3ade to your computer and use it in GitHub Desktop.
$./a.out start forking 1.75534
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <time.h> | |
#include <sys/types.h> | |
#include <sys/time.h> | |
#include <unistd.h> | |
#define SIZE (40 * 1024 * 1024 * 1024L) | |
static inline double get_time_diff_double(struct timeval end, struct timeval start) | |
{ | |
return end.tv_sec - start.tv_sec + (end.tv_usec/1000000.0 - start.tv_usec/1000000.0); | |
} | |
int main(int argc, char** argv) | |
{ | |
char* src = new char[SIZE]; | |
for (long i = 0; i < SIZE; i += 4 * 1024) | |
{ | |
src[i] = 'a'; | |
} | |
struct timeval start, end; | |
std::cout << "start forking" << std::endl; | |
gettimeofday(&start, NULL); | |
if (fork() == 0) | |
{ | |
gettimeofday(&end, NULL); | |
std::cout << get_time_diff_double(end, start) << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment