C#调用IronPython和C方法效率差别

平均调用时间差别一秒左右。

C#调用C++代码:

[DllImport("UseCPP.dll")]
public static extern int Add(int x, int y);

C++代码:

#include "stdafx.h"

extern "C" __declspec(dllexport) int Add(int x, int y)
{
    return x + y;
}

IronPython:

public static int CSUsePyFunc(int x, int y)
        {
            ScriptRuntime pyRT = Python.CreateRuntime();
            dynamic result = pyRT.UseFile("add.py");
            return result.add(x, y);
        }

py代码:

def add(x, y):
    return x + y

运行以后,py调用整整晚了一秒多!

不过py的结果随时都能修改,不需要编译!

原文地址:https://www.cnblogs.com/raddleoj/p/2590793.html