<s> """<STR_LIT>""" <EOL> import django <EOL> from django . core . management . base import NoArgsCommand <EOL> from django . db import connection <EOL> from pprint import pprint <EOL> import sys <EOL> from pexp . models import * <EOL> num_objects = <NUM_LIT:1000> <EOL> def reset_queries ( ) : <EOL> if django . VERSION < ( <NUM_LIT:1> , <NUM_LIT:9> ) : <EOL> connection . queries = [ ] <EOL> else : <EOL> connection . queries_log . clear ( ) <EOL> def show_queries ( ) : <EOL> print <EOL> print '<STR_LIT>' , len ( connection . queries ) <EOL> pprint ( connection . queries ) <EOL> print <EOL> reset_queries ( ) <EOL> import time <EOL> def print_timing ( func , message = '<STR_LIT>' , iterations = <NUM_LIT:1> ) : <EOL> def wrapper ( * arg ) : <EOL> results = [ ] <EOL> reset_queries ( ) <EOL> for i in xrange ( iterations ) : <EOL> t1 = time . time ( ) <EOL> x = func ( * arg ) <EOL> t2 = time . time ( ) <EOL> results . append ( ( t2 - t1 ) * <NUM_LIT> ) <EOL> res_sum = <NUM_LIT:0> <EOL> for r in results : <EOL> res_sum += r <EOL> median = res_sum / len ( results ) <EOL> print '<STR_LIT>' % ( <EOL> message , func . func_name , <EOL> median , <EOL> len ( connection . queries ) / len ( results ) <EOL> ) <EOL> sys . stdout . flush ( ) <EOL> return wrapper <EOL> def run_vanilla_any_poly ( func , iterations = <NUM_LIT:1> ) : <EOL> f = print_timing ( func , '<STR_LIT:U+0020>' , iterations ) <EOL> f ( nModelC ) <EOL> f = print_timing ( func , '<STR_LIT>' , iterations ) <EOL> f ( ModelC ) <EOL> def bench_create ( model ) : <EOL> for i in xrange ( num_objects ) : <EOL> model . objects . create ( field1 = '<STR_LIT:abc>' + str ( i ) , field2 = '<STR_LIT>' + str ( i ) , field3 = '<STR_LIT>' + str ( i ) ) <EOL> def bench_load1 ( model ) : <EOL> for o in model . objects . all ( ) : <EOL> pass <EOL> def bench_load1_short ( model ) : <EOL> for i in xrange ( num_objects / <NUM_LIT:100> ) : <EOL> for o in model . objects . all ( ) [ : <NUM_LIT:100> ] : <EOL> pass <EOL> def bench_load2 ( model ) : <EOL> for o in model . objects . all ( ) : <EOL> f1 = o . field1 <EOL> f2 = o . field2 <EOL> f3 = o . field3 <EOL> def bench_load2_short ( model ) : <EOL> for i in xrange ( num_objects / <NUM_LIT:100> ) : <EOL> for o in model . objects . all ( ) [ : <NUM_LIT:100> ] : <EOL> f1 = o . field1 <EOL> f2 = o . field2 <EOL> f3 = o . field3 <EOL> def bench_delete ( model ) : <EOL> model . objects . all ( ) . delete ( ) <EOL> class Command ( NoArgsCommand ) : <EOL> help = "<STR_LIT>" <EOL> def handle_noargs ( self , ** options ) : <EOL> func_list = [ <EOL> ( bench_delete , <NUM_LIT:1> ) , <EOL> ( bench_create , <NUM_LIT:1> ) , <EOL> ( bench_load1 , <NUM_LIT:5> ) , <EOL> ( bench_load1_short , <NUM_LIT:5> ) , <EOL> ( bench_load2 , <NUM_LIT:5> ) , <EOL> ( bench_load2_short , <NUM_LIT:5> ) <EOL> ] <EOL> for f , iterations in func_list : <EOL> run_vanilla_any_poly ( f , iterations = iterations ) <EOL> print </s>
