<s> """<STR_LIT>""" <EOL> import cProfile <EOL> import os <EOL> import pstats <EOL> import sys <EOL> from google . appengine . ext import testbed <EOL> from google . appengine . ext import db <EOL> from ndb import utils <EOL> utils . DEBUG = False <EOL> from ndb import eventloop <EOL> from ndb import model <EOL> from ndb import tasklets <EOL> os . environ = dict ( os . environ ) <EOL> class Foo ( db . Model ) : <EOL> pass <EOL> def populate ( n ) : <EOL> xs = [ Foo ( ) for i in xrange ( n ) ] <EOL> ks = db . put ( xs ) <EOL> qry = Foo . all ( keys_only = True ) <EOL> def bench ( n ) : <EOL> ks = qry . fetch ( n ) <EOL> assert len ( ks ) == n <EOL> def profiler ( func , n ) : <EOL> prof = cProfile . Profile ( ) <EOL> prof = prof . runctx ( '<STR_LIT>' % ( func . __name__ , n ) , globals ( ) , locals ( ) ) <EOL> stats = pstats . Stats ( prof ) <EOL> stats . strip_dirs ( ) <EOL> stats . sort_stats ( '<STR_LIT:time>' ) <EOL> stats . print_stats ( <NUM_LIT:20> ) <EOL> def main ( ) : <EOL> utils . tweak_logging ( ) <EOL> tb = testbed . Testbed ( ) <EOL> tb . activate ( ) <EOL> tb . init_datastore_v3_stub ( ) <EOL> tb . init_memcache_stub ( ) <EOL> n = <NUM_LIT:1000> <EOL> for arg in sys . argv [ <NUM_LIT:1> : ] : <EOL> try : <EOL> n = int ( arg ) <EOL> break <EOL> except Exception : <EOL> pass <EOL> populate ( n ) <EOL> profiler ( bench , n ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
