亚欧色一区w666天堂,色情一区二区三区免费看,少妇特黄A片一区二区三区,亚洲人成网站999久久久综合,国产av熟女一区二区三区

  • 發布文章
  • 消息中心
點贊
收藏
評論
分享
原創

python3性能加速幾種方式及性能(三)

2023-04-24 08:17:00
10
0

ctypes是傳統的加速方式,先用c++或者c將代碼編譯為動態庫,由ctypes來進行調用。

c++樣例代碼    count.cc

#include <iostream>
#include<iomanip>
#include<time.h>
using namespace std;

extern "C" int count(int n){
    int ans = 0;
    for( int i = 0; i <= n; i+=1 ){
        ans = ans + 1;
    }
    return ans;
}

運行g++ -o count.so -shared -fPIC count.cc -O2 生成動態庫

python3調用測試代碼

from ctypes import *
ctype_handel = cdll.LoadLibrary("./count.so")
print(ctype_handel.count(c_int(9999)))
0條評論
0 / 1000
s****n
8文章數
0粉絲數
s****n
8 文章 | 0 粉絲
原創

python3性能加速幾種方式及性能(三)

2023-04-24 08:17:00
10
0

ctypes是傳統的加速方式,先用c++或者c將代碼編譯為動態庫,由ctypes來進行調用。

c++樣例代碼    count.cc

#include <iostream>
#include<iomanip>
#include<time.h>
using namespace std;

extern "C" int count(int n){
    int ans = 0;
    for( int i = 0; i <= n; i+=1 ){
        ans = ans + 1;
    }
    return ans;
}

運行g++ -o count.so -shared -fPIC count.cc -O2 生成動態庫

python3調用測試代碼

from ctypes import *
ctype_handel = cdll.LoadLibrary("./count.so")
print(ctype_handel.count(c_int(9999)))
文章來自個人專欄
文章 | 訂閱
0條評論
0 / 1000
請輸入你的評論
0
0