Results 1 to 5 of 5

Thread: Python 3 --> Timing factorials.

  1. #1
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152

    Python 3 --> Timing factorials.

    Here, in Python 3, are the times to find n!, for various values of n, on my (slow) computer.

    ' code -------------------------------------------------------------------------------------------
    
    # fact.py
    
    import time
    
    def fact(n):
      fact = 1
      for i in range(1,n+1):
          fact *= i
      return fact
    
    print()
    print("n!     seconds")
    for i in range(10000,210000,10000):
      t1 = time.clock()
      f = fact(i)
      t2 = time.clock()
      print("{0:06d} {1:08.3f}".format(i,t2-t1))
    print()
    
    ' output -----------------------------------------------------------------------------------------
    
    C:\Users\root\Desktop\py>python fact.py
    
    n!     seconds
    010000 0000.189
    020000 0000.796
    030000 0001.931
    040000 0004.924
    050000 0009.093
    060000 0014.278
    070000 0021.162
    080000 0027.877
    090000 0036.518
    100000 0046.368
    110000 0056.992
    120000 0068.359
    130000 0081.301
    140000 0097.560
    150000 0112.566
    160000 0129.895
    170000 0149.381
    180000 0171.193
    190000 0195.403
    200000 0218.713
    
    C:\Users\root\Desktop\py>
    
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Dan,

    do you think you could write down your PC specs (CPU type & frequency, amount of RAM, OS) to get better idea?


    Thanks,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152
    Here is what I could find, Petr.

    Some of this stuff doesn't mean anything to me, maybe it does to you.

    ------------------------------------------------

    emachines EL1200-07w

    Windows Home Premium

    Service Pack 1

    AMD Athlon Processor 2650e 1.60 GHz

    RAM: 2.00 GB (1.75 GB usable)

    32-bit Operating System

    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Thanks Dan, exactly what I needed!


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    i got those timing with python 2.6
    100000 0031.655
    110000 0038.909
    120000 0047.235
    130000 0055.943
    140000 0065.706
    OS is windows xp /sp3
    my cpu is pentium D 3.0 GHz, 3GB ram DDR2.
    my cpu have a mark 814 in passmark cpu, http://www.cpubenchmark.net/cpu_list.php
    while Intel Core i7 995X @ 3.60GHz Passmark is 10945. of course add to that the other capabilities of those mighty processors compared to my old cpu.
    we can see that the i3, i5, i7 are better.

Similar Threads

  1. thinBasic --> Java or Python
    By danbaron in forum Development
    Replies: 9
    Last Post: 19-12-2011, 07:08
  2. learning python?
    By largo_winch in forum Other languages
    Replies: 21
    Last Post: 06-12-2011, 00:05
  3. Lisp: Timing Recursive Factorials
    By danbaron in forum Other languages
    Replies: 0
    Last Post: 18-03-2011, 06:29
  4. Python Sets
    By danbaron in forum Scripting
    Replies: 5
    Last Post: 24-10-2010, 06:10
  5. Python --> Timing a Matrix Inversion
    By danbaron in forum Scripting
    Replies: 3
    Last Post: 16-07-2010, 04:02

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •