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

    Join Date
    Dec 2012
    Posts
    76
    Rep Power
    2

    Finding the "timeit" dir (or just ignoring it)


    So, I have found a way to smooth (for me, at least) utilization of the timeit module by feeding it separate lambda decorators within a pickle so that I don't have to feed it the script of the actual functions each time.

    However, I swiftly realized that timeit's Python shell doesn't EXIST in the same location that the script that is running is.

    So either of these answers will suffice, preferably the second:

    --Where is timeit's shell?
    --How do I get my current directory, so that I may feed it to timeit?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    I agree, whenever I use timeit I feel like I've had to use some funny kludge via the setup code. I'd have thought there'd be a way to easily pass in globals and locals.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    76
    Rep Power
    2
    Well, I'd be happy to share it with you once I get it done.
    Basically, it just pickles the two functions before timeit is even run, then passes a setup code that knows where to find the pickles, and un-pickles them.

    I just need to know how to get the directory that my script is running from so that I can save the pickles to the same directory that I call them from.

    I need to get the full path data, i.e. "C:\\..." because a relative path directory just tries to find the pickles based on the directory the shell is in (wherever that is)
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    You could use timeit to execute a code that writes the result of
    os.getcwd()
    to a file that you could later read.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    76
    Rep Power
    2
    Thank you so much.

    Well, the code doesn't need to write a file with the code at all, it does everything via the fact that functions are pickle-able objects. I have one module that just pickles or un-pickles "Whatever I feed it, from wherever I ask" from a given location, and so I just import that module in Python and in the shell.

    I doubt you can help here, this error is really weird...

    Code:
    Traceback (most recent call last):
      File "C:\Documents and Settings\*****\Desktop\Console\benchmarking.py", line 26, in <module>
        benchmark(1000,**test)
      File "C:\Documents and Settings\*****\Desktop\Console\benchmarking.py", line 16, in benchmark
        result=timeit.timeit(test,setup,runcount)
      File "C:\Python27\lib\timeit.py", line 230, in timeit
        return Timer(stmt, setup, timer).timeit(number)
      File "C:\Python27\lib\timeit.py", line 136, in __init__
        code = compile(src, dummy_src_name, "exec")
      File "<timeit-src>", line 4
        pull= storage_functions(extension=".tmp",location="C:\Documents and Settings\*****\Desktop\Console\Temp\")[0]
    Do you know why that's giving me an EOL error?

IMN logo majestic logo threadwatch logo seochat tools logo