Import statements for timeit module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ChaosKCW

    #1

    Import statements for timeit module

    Hi

    I was wondering if someone could help with the import statements needed
    to use the timeit module in the following code. I need to access the
    "cur" object.

    Thanks,

    import cx_Oracle
    import timeit

    def VerifyTagIntegr ity(con, TableOwner):
    cur = con.cursor()
    sql = 'select (select count(*) from %s.f4111) as F4111_COUNT,
    (select count(*) from %s.f4111_tag) as TAG_COUNT from dual;' %
    (TableOwner, TableOwner)
    print " SQL: %s" % (sql)
    timer = timeit.Timer('c ur.execute(sql) ', 'from __main__ import
    cur')
    print timer.timeit()

  • bruno at modulix

    #2
    Re: Import statements for timeit module

    ChaosKCW wrote:[color=blue]
    > Hi
    >
    > I was wondering if someone could help with the import statements needed
    > to use the timeit module in the following code. I need to access the
    > "cur" object.
    >
    > Thanks,
    >
    > import cx_Oracle
    > import timeit
    >
    > def VerifyTagIntegr ity(con, TableOwner):
    > cur = con.cursor()
    > sql = 'select (select count(*) from %s.f4111) as F4111_COUNT,
    > (select count(*) from %s.f4111_tag) as TAG_COUNT from dual;' %
    > (TableOwner, TableOwner)
    > print " SQL: %s" % (sql)
    > timer = timeit.Timer('c ur.execute(sql) ', 'from __main__ import
    > cur')
    > print timer.timeit()
    >[/color]

    'cur' is local to the function, so it's not an attribute of your module,
    so you can't hope to import it anyway.


    --
    bruno desthuilliers
    python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
    p in 'onurb@xiludom. gro'.split('@')])"

    Comment

    • ChaosKCW

      #3
      Re: Import statements for timeit module

      So timeit is mostly useless then ?

      Comment

      • Alex Martelli

        #4
        Re: Import statements for timeit module

        ChaosKCW <da.martian@gma il.com> wrote:
        [color=blue]
        > So timeit is mostly useless then ?[/color]

        No, it's a precious jewel, but if you want to use it you must allow it
        to import the code you want it to run.


        Alex

        Comment

        • Scott David Daniels

          #5
          Re: Import statements for timeit module

          bruno at modulix wrote:[color=blue]
          > ChaosKCW wrote:
          >[color=green]
          >>Hi
          >>
          >>I was wondering if someone could help with the import statements needed
          >>to use the timeit module in the following code. I need to access the
          >>"cur" object.
          >>
          >>Thanks,
          >>[/color][/color]
          ....>[color=blue]
          > 'cur' is local to the function, so it's not an attribute of your module,
          > so you can't hope to import it anyway.[/color]

          Although you could change your code as follows:
          [color=blue][color=green]
          >>import cx_Oracle
          >>import timeit
          >>
          >>def VerifyTagIntegr ity(con, TableOwner):[/color][/color]
          global cur, sql ###[color=blue][color=green]
          >> cur = con.cursor()
          >> sql = 'select (select count(*) from %s.f4111) as F4111_COUNT,
          >>(select count(*) from %s.f4111_tag) as TAG_COUNT from dual;' %
          >>(TableOwner , TableOwner)
          >> print " SQL: %s" % (sql)[/color][/color]
          XXX>> timer = timeit.Timer('c ur.execute(sql) ', 'from __main__ import[color=blue][color=green]
          >>cur')[/color][/color]
          timer = timeit.Timer('c ur.execute(sql) ', ###
          'from __main__ import cur, sql') ###[color=blue][color=green]
          >> print timer.timeit()[/color][/color]

          --
          -Scott David Daniels
          scott.daniels@a cm.org

          Comment

          • bruno at modulix

            #6
            Re: Import statements for timeit module

            ChaosKCW wrote:[color=blue]
            > So timeit is mostly useless then ?
            >[/color]
            I wouldn't say so.

            --
            bruno desthuilliers
            python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
            p in 'onurb@xiludom. gro'.split('@')])"

            Comment

            Working...