C# application works much slower using compiled IronPython standard library

て烟熏妆下的殇ゞ 提交于 2019-12-22 11:22:43

问题


When I load modules from standard library as source .py files in this application, elapsed time after end equals approximately 4 seconds:

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();

But when I load modules from standard library compiled using script:

import System
import pyc
def get_files(dir):
    res = [file for file in System.IO.Directory.GetFiles(dir, '*.py')]
    dirs = System.IO.Directory.GetDirectories(dir)
    if dirs:
        for dir in dirs:
            res += get_files(dir)
    return res
files = get_files(r'C:\Program Files (x86)\IronPython 2.7.1\Lib')
pyc.Main(files + ['/out:IronPython.Stdlib'])

in this application, elapsed time after end equals approximately 20 seconds:

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();

Why loading modules from precompiled library is much slower than loading from source files?

来源:https://stackoverflow.com/questions/9017257/c-sharp-application-works-much-slower-using-compiled-ironpython-standard-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!