#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    16
    Rep Power
    0

    how can i calculate time to run a task ???


    how can i calculate the time to run my function in Python? Can you help me, thanks .
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Hi!

    Code:
    import time
    
    def your_function():
        # whatever your function does
    
    loops = 10000    # how often your function is called
    begin = time.time()
    for x in range(loops):
         your_function()
    print "%0.3fs" % (time.time() - begin)
    Regards, mawe
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    yes and to give alittle feedback...

    mutliply the total time for one function timing times the number you want to run it and then you have the total time left if you subtract the time you already did....
    Those people who think they know everything are a great annoyance to those of us who do.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    monkeyman, maybe it's because english is not my mother tongue, but I have no idea what you mean
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    Okay I meant that your way is to see how long it takes to run all of them and mine is how long it takes to run one and then calculate the rest of the time or something like that...

    I am not mother tongue either

    Code:
    >>> def func(times,function,*args):
    	start = time.clock()
    	function(args)
    	end = time.clock()
    	Time = "%f" % (end - start)
    	print str(float(Time)*times)+"s"
    Thats my code for this thing and I did not run all of them I only ran it once...

    It probably does not work to great not very accurate but i hope you get my point...
    Last edited by monkeyman23555; July 15th, 2005 at 12:16 PM.
    Those people who think they know everything are a great annoyance to those of us who do.
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I would also suggest using time.time() instead of time.clock() for improved compatibility between platforms. It also give better results IMO and is easier to understand .

    Mark.

    Comments on this post

    • CyBerHigh agrees
    • xlordt agrees
    • LinuxPenguin agrees
    programming language development: www.netytan.com Hula

  12. #7
  13. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by netytan
    I would also suggest using time.time() instead of time.clock() for improved compatibility between platforms. It also give better results IMO and is easier to understand .

    Mark.
    Not only that.. but time.time( ) works alot faster then time.clock( ) as they are for different purpose's
  14. #8
  15. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    If you check the Python Library Reference, you will find that the Profiler module has classes and functions for this purpose; for a single function, you probably can use timeit.Timer, while for more detailed profiling you should use profile.run() and pstats.Stats.
    Last edited by Schol-R-LEA; July 18th, 2005 at 02:40 AM.
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    hi about the time.clock I just used it because the other time.time did not work???

    I don't know why...
    Those people who think they know everything are a great annoyance to those of us who do.

IMN logo majestic logo threadwatch logo seochat tools logo