Skip to content

Instantly share code, notes, and snippets.

@wangzaixiang
Created September 17, 2012 12:43
Show Gist options
  • Save wangzaixiang/3737077 to your computer and use it in GitHub Desktop.
Save wangzaixiang/3737077 to your computer and use it in GitHub Desktop.
pth uctx switch cost
#include <pth.h>
#include <stdio.h>
#include <sys/time.h>
pth_uctx_t u_main;
pth_uctx_t u_test;
char stack[16*1024];
void test(void *);
const int LOOP = 1000*1000;
main(){
pth_uctx_create(&u_main);
pth_uctx_create(&u_test);
pth_uctx_make(u_test, stack, sizeof(stack), NULL, test, NULL, NULL);
struct timeval begin, end;
gettimeofday(&begin, NULL);
for(int i=0; i<LOOP; i++) {
pth_uctx_switch(u_main, u_test);
}
gettimeofday(&end, NULL);
printf("total time = %d\n", (end.tv_sec-begin.tv_sec)*1000*1000 + (end.tv_usec-begin.tv_usec));
}
void test(void* arg){
for(int i=0; i<LOOP; i++){
pth_uctx_switch(u_test, u_main);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment