yyzybb537 / libgo

Go-style concurrency in C++11
MIT License
3.2k stars 756 forks source link

空载延迟达到20us #309

Open bethebest0622 opened 8 months ago

bethebest0622 commented 8 months ago
int main() {
  co_sched.goStart(0);

  timeval t;
  gettimeofday(&t, NULL);

  go [] {}; 

  timeval t2; 
  gettimeofday(&t2, NULL);

  int latency = (t2.tv_sec - t.tv_sec) * 1000000 + (t2.tv_usec - t.tv_usec);

  printf("cost %d\n", latency);

这段代码需要20us,空载的延迟这么高吗

paradiseforgithub commented 8 months ago

已收到您的邮件,如有问题会尽快给您回复. 

hnwyllmm commented 8 months ago

仅仅测试单个耗时极短的函数开销意义不大,毕竟gettimeofday也是有开销的。可以循环运行百万次、千万次以使误差更小。

nqf commented 8 months ago

image

bethebest0622 commented 8 months ago

image

可以加个vx聊聊吗