<p>对于这类问题,您可以使用<a href="https://docs.python.org/2/library/timeit.html" rel="nofollow">timeit</a>模块检查所用的时间,如下所示</p>
<pre><code>Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import timeit
>>>
>>>
>>> code_to_test_1 = """
... text = 'Allah is all in all. Allah sees you, and is with you, wherever you are, whatever you do.'
...
... wahed_al_surat = text.split(',')[0]
... thalatha_al_surat = text.split(',')[1]
... tnan_al_surat = text.split(',')[2]
... arbaa_al_surat = text.split(',')[3]
... """
>>>
>>>
>>> code_to_test_2 = """
... text = 'Allah is all in all. Allah sees you, and is with you, wherever you are, whatever you do.'
...
... splitted = text.split(',') # List accessible by split
... wahed_al_surat = splitted[0]
... thalatha_al_surat = splitted[1]
... tnan_al_surat = splitted[2]
... arbaa_al_surat = splitted[3]
... """
>>>
>>>
>>> timeit.timeit(code_to_test_1, number=10000000)
14.445806980133057
>>>
>>>
>>> timeit.timeit(code_to_test_2, number=10000000)
4.4506120681762695
>>>
</code></pre>