<s> import warnings <EOL> warnings . filterwarnings ( "<STR_LIT:ignore>" , r"<STR_LIT>" ) <EOL> try : <EOL> import cdecimal <EOL> import sys <EOL> sys . modules [ '<STR_LIT>' ] = cdecimal <EOL> except ImportError : <EOL> pass <EOL> from sqlalchemy import __version__ <EOL> from sqlalchemy import Column , Integer , create_engine , ForeignKey , String , Numeric <EOL> from sqlalchemy . orm import Session , relationship <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> import random <EOL> import os <EOL> from decimal import Decimal <EOL> Base = declarative_base ( ) <EOL> class Employee ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> name = Column ( String ( <NUM_LIT:100> ) , nullable = False ) <EOL> type = Column ( String ( <NUM_LIT:50> ) , nullable = False ) <EOL> __mapper_args__ = { '<STR_LIT>' : type } <EOL> class Boss ( Employee ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , primary_key = True ) <EOL> golf_average = Column ( Numeric ) <EOL> __mapper_args__ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> class Grunt ( Employee ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , primary_key = True ) <EOL> savings = Column ( Numeric ) <EOL> employer_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> employer = relationship ( "<STR_LIT>" , backref = "<STR_LIT>" , <EOL> primaryjoin = Boss . id == employer_id ) <EOL> __mapper_args__ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> os . remove ( '<STR_LIT>' ) <EOL> engine = create_engine ( '<STR_LIT>' ) <EOL> Base . metadata . create_all ( engine ) <EOL> sess = Session ( engine ) <EOL> def runit ( status , factor = <NUM_LIT:1> , query_runs = <NUM_LIT:5> ) : <EOL> num_bosses = <NUM_LIT:100> * factor <EOL> num_grunts = num_bosses * <NUM_LIT:100> <EOL> bosses = [ <EOL> Boss ( <EOL> name = "<STR_LIT>" % i , <EOL> golf_average = Decimal ( random . randint ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> ) <EOL> for i in range ( num_bosses ) <EOL> ] <EOL> sess . add_all ( bosses ) <EOL> status ( "<STR_LIT>" % num_bosses ) <EOL> grunts = [ <EOL> Grunt ( <EOL> name = "<STR_LIT>" % i , <EOL> savings = Decimal ( random . randint ( <NUM_LIT> , <NUM_LIT> ) / <NUM_LIT:100> ) <EOL> ) <EOL> for i in range ( num_grunts ) <EOL> ] <EOL> status ( "<STR_LIT>" % num_grunts ) <EOL> while grunts : <EOL> batch_size = <NUM_LIT:100> <EOL> batch_num = ( num_grunts - len ( grunts ) ) / batch_size <EOL> boss = sess . query ( Boss ) . filter_by ( name = "<STR_LIT>" % batch_num ) . first ( ) <EOL> for grunt in grunts [ <NUM_LIT:0> : batch_size ] : <EOL> grunt . employer = boss <EOL> grunts = grunts [ batch_size : ] <EOL> sess . commit ( ) <EOL> status ( "<STR_LIT>" ) <EOL> for i in range ( query_runs ) : <EOL> status ( "<STR_LIT>" % ( i + <NUM_LIT:1> ) ) <EOL> report = [ ] <EOL> for grunt in sess . query ( Grunt ) : <EOL> report . append ( ( <EOL> grunt . name , <EOL> grunt . savings , <EOL> grunt . employer . name , <EOL> grunt . employer . golf_average <EOL> ) ) <EOL> sess . close ( ) <EOL> def run_with_profile ( runsnake = False , dump = False ) : <EOL> import cProfile <EOL> import pstats <EOL> filename = "<STR_LIT>" <EOL> if os . path . exists ( "<STR_LIT>" ) : <EOL> os . remove ( "<STR_LIT>" ) <EOL> def status ( msg ) : <EOL> print ( msg ) <EOL> cProfile . runctx ( '<STR_LIT>' , globals ( ) , locals ( ) , filename ) <EOL> stats = pstats . Stats ( filename ) <EOL> counts_by_methname = dict ( ( key [ <NUM_LIT:2> ] , stats . stats [ key ] [ <NUM_LIT:0> ] ) for key in stats . stats ) <EOL> print ( "<STR_LIT>" % __version__ ) <EOL> print ( "<STR_LIT>" % stats . total_calls ) <EOL> print ( "<STR_LIT>" % stats . total_tt ) <EOL> print ( '<STR_LIT>' % counts_by_methname [ "<STR_LIT>" <EOL> "<STR_LIT>" ] ) <EOL> print ( '<STR_LIT>' % counts_by_methname . get ( "<STR_LIT>" <EOL> "<STR_LIT>" , <NUM_LIT:0> ) ) <EOL> if dump : <EOL> stats . sort_stats ( '<STR_LIT:time>' , '<STR_LIT>' ) <EOL> stats . print_stats ( ) <EOL> if runsnake : <EOL> os . system ( "<STR_LIT>" % filename ) <EOL> def run_with_time ( ) : <EOL> import time <EOL> now = time . time ( ) <EOL> def status ( msg ) : <EOL> print ( "<STR_LIT>" % ( time . time ( ) - now , msg ) ) <EOL> runit ( status , <NUM_LIT:10> ) <EOL> print ( "<STR_LIT>" % ( time . time ( ) - now ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import argparse <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> args . profile = args . profile or args . dump or args . runsnake <EOL> if args . profile : <EOL> run_with_profile ( runsnake = args . runsnake , dump = args . dump ) <EOL> else : <EOL> run_with_time ( ) </s>
