Differences between revisions 3 and 4
Revision 3 as of 2008-04-03 13:37:51
Size: 1872
Editor: ZoomQuiet
Comment:
Revision 4 as of 2008-04-03 13:56:31
Size: 2288
Editor: ZoomQuiet
Comment:
Deletions are marked like this. Additions are marked like this.
Line 88: Line 88:
== time vs 0.3 ==
attachment:vs-0.3.png

=== random0.2.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()
    
}}}

TableOfContents

Include(ZPyUGnav)

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

random.pl

use strict;


open (WW,"> 500000") or die "$!";
foreach(1..5000000){
my $i = int(rand 10000000) % 3;
print WW $i."\n";
}
close WW; 

random.py

   1 import random
   2 import time
   3 
   4 __revision__ = '0.1'
   5 
   6 def test():
   7     fh = open("test_cjj","w")
   8    
   9     for i in range(5000000):
  10         data = random.randrange(1000000,9999999,1)
  11         yu = data % 3
  12         fh.write(str(yu)+"\n")
  13                                                   
  14     fh.close()
  15 
  16 if __name__ == "__main__" :
  17     test()

time vs 0.2

attachment:vs-0.2.png

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

random0.2.py

   1 import random
   2 import time
   3 
   4 __revision__ = '0.3'
   5 
   6 def test():    
   7     exp = ""
   8     for i in xrange(5000000):
   9         data = random.randrange(1000000,9999999,1)
  10         exp += "%s\n"%(str(data % 3))                             
  11    
  12     open("test_cjj0.3","w").write(exp)
  13 if __name__ == "__main__" :
  14     test()


反馈

创建 by -- ZoomQuiet [DateTime(2008-04-03T13:26:48Z)]

PageComment2

[:/PageCommentData:PageCommentData]

MiscItems/2008-04-03 (last edited 2009-12-25 07:08:58 by localhost)