使用编译好的IronPython标准库,C#应用程序的运行速度要慢得多

使用编译好的IronPython标准库,C#应用程序的运行速度要慢得多,c#,.net,ironpython,dynamic-language-runtime,C#,.net,Ironpython,Dynamic Language Runtime,在此应用程序中,当我将标准库中的模块作为源.py文件加载时,结束后经过的时间约为4秒: Stopwatch watch = Stopwatch.StartNew(); ScriptEngine engine = Python.CreateEngine(); ScriptScope scope = engine.CreateScope(); ICollection<string> paths = engine.GetSearchPaths(); paths.Add(@"C:\Users

在此应用程序中,当我将标准库中的模块作为源.py文件加载时,结束后经过的时间约为4秒:

Stopwatch watch = Stopwatch.StartNew();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
ICollection<string> paths = engine.GetSearchPaths();
paths.Add(@"C:\Users\Montgomery1944\Documents\Libs\IronPython-2.7.1\Lib");
engine.SetSearchPaths(paths);
ScriptSource source = engine.CreateScriptSourceFromString(
@"from distutils import dir_util
import ftplib
import os
import tempfile
import zipfile");
source.Execute(scope);
watch.Stop();
Console.WriteLine(watch.Elapsed.Seconds);
Console.ReadLine();
在此应用程序中,结束后经过的时间约为20秒:

Stopwatch watch = Stopwatch.StartNew();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
ScriptSource source = engine.CreateScriptSourceFromString(
@"import clr
clr.AddReference('IronPython.Stdlib')
from distutils import dir_util
import ftplib
import os
import tempfile
import zipfile");
source.Execute(scope);
watch.Stop();
Console.WriteLine(watch.Elapsed.Seconds);
Console.ReadLine();

为什么从预编译库加载模块要比从源文件加载慢得多?

您无法比较两者。只有在第二种情况下,您才能使用AddReference导入clr。是的,我可以比较它,在第一个应用程序中,我使用“path.Add(@“C:\Users\Montgomery1944\Documents\Libs\IronPython-2.7.1\Lib”)”包含标准库,在第二个应用程序中使用“clr.AddReference('IronPython.Stdlib')”,它是相同的标准库,但形式不同。至于我,编译版本的加载应该更快,但事实并非如此。是的,但在第一种情况下,您还没有使用clr。我认为这是一个陷阱。我认为,如果您只运行@“import clr clr.AddReference('IronPython.Stdlib'),则更像是一个包含标准库中所有内容的编译库)需要多长时间?您无法比较两者。只有在第二种情况下,您才能使用AddReference导入clr。是的,我可以进行比较,在第一个应用程序中,我使用“path.Add”(@“C:\Users\Montgomery1944\Documents\Libs\IronPython-2.7.1\Lib”)、在第二个应用程序中使用“clr.AddReference('IronPython.Stdlib'))包含标准库,它是相同的标准库,但形式不同。至于我,编译版本的加载应该更快,但事实并非如此。是的,但在第一种情况下,您还没有使用clr。我认为这是一个陷阱。我认为这更像是一个包含标准库中所有内容的编译库,如果您只运行@“import clr clr.AddReference('IronPython.Stdlib')),需要多长时间?
Stopwatch watch = Stopwatch.StartNew();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
ScriptSource source = engine.CreateScriptSourceFromString(
@"import clr
clr.AddReference('IronPython.Stdlib')
from distutils import dir_util
import ftplib
import os
import tempfile
import zipfile");
source.Execute(scope);
watch.Stop();
Console.WriteLine(watch.Elapsed.Seconds);
Console.ReadLine();