Skip to content Skip to sidebar Skip to footer

String Performance - Python 2.7 Vs Python 3.4 Under Windows 10 Vs. Ubuntu

Use case A simple function which checks if a specific string is in another string at a position which is a multiple of 3 (see here for a real world example, finding stop codons in

Solution 1:

Although you are measuring speed of the same code, the structures in your code are different.

A. range in 2.7 is type 'list', range in 3.4 is class 'range'

B. 'ATG' * 10**6 in 2.7 is a bytes string and in 3.4 it's and unicode string

You can try to produce more compatible results if: a) use xrange for 2.7 variant, b) use bytes string in both examples: b'ATG' or unicode strings in both examples.

Update

I suspected that difference in performance stems from main factors: a) 32bit vs 64bit, b) C compiler.

So, I did tests for:

  1. ActiveState Python 2.7.10 32bit
  2. ActiveState Python 2.7.10 64bit
  3. Official distribution Python 2.7.11 32bit
  4. Official distribution Python 2.7.11 64bit
  5. Python 2.7.6 64bit on Ubuntu on Windows 10
  6. pypy-5.1.1-win32

What I expected

I expected that:

  • 64bit version will be slower
  • ActiveState will be a little faster
  • PyPy faster by magnitude
  • Ubuntu on Windows 10 - ???

Results

Testas32bas64boff32boff64bubw64bpypy5.1.1Sliding,regular:1.2321.2301.2811.1360.9510.099Incremental,regular:1.7441.6902.2191.6471.4722.772Sliding,byte string:1.2231.2071.2801.1270.9260.101Incremental,bytes:1.7201.7012.2061.6461.5682.774Sliding,xrange&bytes:1.1171.1021.1620.9620.7790.109simple find in string:3.4433.4124.6073.3002.4870.289

And the winner on Windows 10 is .... Ubuntu Python compiled by GCC 4.8.2 for Linux!

This result was completely unexpected for me.

32 vs 64: turned irrelevant.

PyPy: as always megafast, except cases when it's not.

I can't interprete this results, OP question turned not so simple as it seemed.

Post a Comment for "String Performance - Python 2.7 Vs Python 3.4 Under Windows 10 Vs. Ubuntu"