Size: 1420
Comment:
|
Size: 3877
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 8: | Line 8: |
##startInc | |
Line 21: | Line 22: |
=== random.pl === | === 5" random.pl === |
Line 35: | Line 36: |
=== random.py === | === 31" random.py === |
Line 58: | Line 59: |
attachment:vs-0.1.png === random0.2.py === {{{#!python }}} ##startInc |
attachment:vs-0.2.png === 48" random0.2.py === {{{#!python import cStringIO as StringIO import random import time __revision__ = '0.2' def test(): fh = open("test_cjj0.2","w") output = StringIO.StringIO() for i in xrange(5000000): data = random.randrange(1000000,9999999,1) yu = data % 3 print >>output, yu fh.write(output.getvalue()) fh.close() if __name__ == "__main__" : test() }}} == time vs 0.3 == attachment:vs-0.3.png === 33" random0.3.py === {{{#!python import random import time __revision__ = '0.3' def test(): exp = "" for i in xrange(5000000): data = random.randrange(1000000,9999999,1) exp += "%s\n"%(str(data % 3)) open("test_cjj0.3","w").write(exp) if __name__ == "__main__" : test() }}} == time vs 0.4 == attachment:vs-0.4.png === 27" random0.4.py === {{{#!python import random __revision__ = '0.4' fn = open("test_cjj0.4","w") for i in xrange(5000000): data = random.randrange(1000000,9999999,1) print >> fn, (data % 3) }}} == time vs 0.5 == attachment:vs-0.5.png === 51" random0.5.py === {{{#!python import cStringIO as StringIO import random __revision__ = '0.5' #fn = open("test_cjj0.4","w") out = StringIO.StringIO() for i in xrange(5000000): data = random.randrange(1000000,9999999,1) print >> out, (data % 3) open("test_cjj0.5","w").write(out.getvalue()) }}} == time vs 0.6 == attachment:vs-0.6.png === 26" random0.6.py === {{{#!python import random __revision__ = '0.6' fn = open("test_cjj0.6","w") for i in xrange(5000000): print >> fn, (random.randrange(1000000,9999999,1))% 3 }}} == time vs 0.7 == attachment:vs-0.7.png === 10" random0.7.py === {{{#!python from random import random __revision__ = '0.7' fh = open("test_cjj0.7","w") for i in range(5000000): print >> fh,(int(random()*(9999999-1000000)+1000000))% 3 }}} == time vs 0.8 == attachment:vs-0.8.png === 5" random0.8.py === {{{#!python from random import random __revision__ = '0.8' def test(): fh = open("test_cjj0.8","w") for i in range(5000000): print >> fh,(int(random()*(9999999-1000000)+1000000))% 3 if __name__ == "__main__" : try: import psyco psyco.full() except ImportError: pass test() }}} |
Py vs Perl 运行
{{{俊杰蔡 <[email protected]> reply-to [email protected], to [email protected], date Thu, Apr 3, 2008 at 5:50 PM subject [CPyUG:45860] }}} [http://groups.google.com/group/python-cn/browse_thread/thread/4e4eb6d67a867c21/8b346859a4c96e29#8b346859a4c96e29 一段python程序的效率问题]
time vs 0.1
attachment:vs-0.1.png
5" random.pl
use strict; open (WW,"> 500000") or die "$!"; foreach(1..5000000){ my $i = int(rand 10000000) % 3; print WW $i."\n"; } close WW;
31" random.py
time vs 0.2
attachment:vs-0.2.png
48" random0.2.py
1 import cStringIO as StringIO
2
3 import random
4 import time
5
6 __revision__ = '0.2'
7
8 def test():
9 fh = open("test_cjj0.2","w")
10 output = StringIO.StringIO()
11
12 for i in xrange(5000000):
13
14 data = random.randrange(1000000,9999999,1)
15 yu = data % 3
16 print >>output, yu
17
18 fh.write(output.getvalue())
19
20 fh.close()
21
22 if __name__ == "__main__" :
23 test()
time vs 0.3
attachment:vs-0.3.png
33" random0.3.py
time vs 0.4
attachment:vs-0.4.png
27" random0.4.py
time vs 0.5
attachment:vs-0.5.png
51" random0.5.py
time vs 0.6
attachment:vs-0.6.png
26" random0.6.py
time vs 0.7
attachment:vs-0.7.png
10" random0.7.py
time vs 0.8
attachment:vs-0.8.png
5" random0.8.py
反馈
创建 by -- ZoomQuiet [DateTime(2008-04-03T13:26:48Z)]