The first thing I tried to get this running faster was psyco.
为了让它跑得更快,我首先尝试了psyco.
The first line tells Psyco to do its magic on all global functions.
第一行告诉Psyco对所有全局函数“发挥其魔力”。
As of right now, Psyco is only available for i386 CPU architectures.
到现在为止,Psyco只可用于i386CPU体系结构。
Explaining Psyco is relatively difficult, but using Psyco is far easier.
解释Psyco相对比较困难,但是使用Psyco就非常容易了。
Psyco replaces the eval_frame() function with a compound evaluation unit.
Psyco用复合求值单元替代 eval_frame()函数。
As magic as Psyco is, using it still requires a little thought and testing.
尽管Psyco如此神奇,使用它仍然需要一点思考和测试。
For Psyco, there are "run-time," "compile-time" and "virtual-time" variables.
对于Psyco,有“运行时”、“编译时”和“虚拟时”变量。
Unlike the other techniques described, Psyco operates strictly at Python runtime.
和所描述的其它技术不同,Psyco 是严格地在Python运行时进行操作的。
After a little playing around, I established several details about how to use Psyco.
使用了一段时间后,我建立了有关psyco用法的一些详细信息。
More significantly, however, it is important to understand the scope of Psyco binding.
然而,更值得注意的是要理解Psyco绑定的作用域,这一点很重要。
Psyco has a large memory overhead which might even negate any gains if the machine has to go to swap.
Psyco 需要很大的内存开销,如果机器进入交换,它甚至会抵销 Python 获得的任何性能。
The Psyco module is an often-missed way to increase the speed of Python applications with minimal work.
Psyco模块常常被忽略,但是它可以通过较少的工作提高Python应用程序的速度。
Psyco — to keep it very short — is a just-in-time (JIT) compiler of Python code into (x86) machine code.
Psyco可以保持代码非常简短;它是(x86)机器代码中的一个JITPython代码编译器。
Psyco: Learn more about this Python extension module that can massively speed up the execution of Python code.
Psyco:了解有关这个Python扩展模块的更多信息,它可以显著提高Python代码的执行速度。
The real savings in Psyco, however, arise from Psyco's categorization of operations into three different levels.
但是,Psyco中真正省时的原因在于 Psyco 将操作分成三个不同的级别。
When I ran Listing 4 with Psyco enabled, I reduced runtime by only three seconds (43.9 seconds versus 47.3 seconds).
当我在启用Psyco的情况下运行清单4时,运行时间仅仅减少了3秒(43.9秒对47.3秒)。
Aside from creating i386-specific codes for small operations, Psyco caches this compiled machine code for later reuse.
除为小型操作创建特定于i386的代码之外,Psyco还高速缓存这个已编译的机器码以备今后重用。
Psyco skips the objects, and just computes the values, knowing that an object can be created "if needed" from the value.
而 Psyco跳过这些对象,只计算这些值,因为它知道“如果需要”,可以从值创建一个对象。
For a more relevant test of Psyco, I dug up some neural network code that I had written about in an earlier article (see Resources).
为进行更恰当的Psyco测试,我搜寻出我在以前的文章里编写的一些神经网络代码(请参阅“参考资料”)。
In addition, perhaps a future Psyco could decide to perform more extensive (but more costly) optimizations on heavily-run operations.
另外,也许今后的Psyco可能会决定对费力运行的操作进行更广泛(但也更昂贵)的优化。
To get Psyco to do the desired optimization, you need to either add psyco.bind(NN) to code_recognizer.py or add psyco.jit() to bpnn.py.
要使Psyco 进行期望的优化,需要将psyco.bind(NN)添加到 code_recognizer.py或者将psyco.jit() 添加到bpnn.py 。
Psyco currently does not perform any sort of internal statistics or profiling, and does only minimal optimization of generated machine code.
Psyco现在不执行任何类型的内部统计或概要分析,只对生成的机器码进行最小优化。
To understand Psyco completely, you probably need to have a good grasp of both the Python interpreter's eval_frame function and i386 Assembly.
要完全理解Psyco,您可能需要很好地掌握python解释器的eval _ frame函数和i386汇编语言。
The nice thing about Psyco is that you can use the very same Python code you have been writing all along (literally!), but let it run much faster.
Psyco的妙处在于可以使用您一直在编写的Python代码(完全一样!),却可以让它运行得更快。
For non-looping functions, and for operations on other types of objects, Psyco mostly just adds overhead for its analysis and internal-compilation.
对于非循环函数和其它类型对象的操作,Psyco多半只会增加其分析和内部编译的开销。
Although I suspect it will never actually happen, it would be exciting to have Psyco-type technology integrated into some future version of Python itself.
若将psyco类型的技术集成到Python本身的某个未来版本中去,会多么令人激动,尽管我怀疑这永远不会真正发生。
The second line (in Python 2.2 and above) tells Psyco to do the same with class methods. To target Psyco's behavior a bit more precisely, you can use the commands.
第二行(在Python 2.2及以上版本中)告诉Psyco对类方法执行相同的操作。
Moreover, in many cases, a generic two lines enabling Psyco can produce an improvement similar to what you get though a moderate degree of rewriting from Python into Pyrex.
而且,在很多情况中,增加两行代码启用Psyco 就可以达到将Python 代码中度修改为Pyrex所能达到的加速效果。
But while the Python interpreter is running an application, Psyco sometimes checks to see if it can substitute some specialized machine code for regular Python bytecode actions.
但是当Python解释器运行应用程序时,Psyco会不时地检查,看是否能用一些专门的机器代码去替换常规的python字节码操作。
The main thing to understand is that Psyco is useful for handling blocks that loop many times, and it knows how to optimize operations involving integers and floating point numbers.
主要是要明白Psyco对于处理多次循环的块是很有用的,而且它知道如何优化涉及整数和浮点数的操作。
应用推荐