以下代码为博客
《Python的并行求和例子》:
http://www.cnblogs.com/instant7/p/4312786.html
中并行python代码的C语言重写版。
用C来跑一遍单线程也只需要50秒,比python 开4进程的实现要快6倍多,CPU占用率也只用python的1/4。
看来计算密集型应用还是需要用这些不顺手的老古董来弄的:)
#include <stdio.h> #include <string.h> #include <iostream> #include <fstream> #include <time.h> using namespace std; char *trim(char *str) { char *p = str; while (*p == ' ' || *p == ' ' || *p == ' ' || *p == ' ') p ++; str = p; p = str + strlen(str) - 1; while (*p == ' ' || *p == ' ' || *p == ' ' || *p == ' ') -- p; *(p + 1) = '