It's taking my machine quite a long time to execute 1 billion (1st loop x 10, 2nd loop x 1000, 3rd loop x 100,000) instructions. Suggestions for performance enhancements? Sources of potential concern: global variables slower than local variables?using for loops instead of something like map?overhead for class instantiation?overhead of storing results in a dictionary before making a pandas frame? from numpy import randomfrom pandas import DataFrame, concatclass coin(object):    HEADS = 1    TAILS = 0    FLIP_TIMES = 10    def __init__(self):                self.frequency = self.flip10()    def flip10(self):               choices = [coin.HEADS, coin.TAILS]        record = []        for i in xrange(coin.FLIP_TIMES):                        record.append(random.choice(choices))        return sum(record) / float(coin.FLIP_TIMES)class trial(object):    NUM_COINS = 1000    DEFAULT_VAL = 11.0 / 10.0    C_RAND_IDX = random.randint(0, NUM_COINS)    def __init__(self):        self.results = self.flip1000()    def flip1000(self):        v_rand = trial.DEFAULT_VAL        v_first = trial.DEFAULT_VAL        v_min = trial.DEFAULT_VAL        for i in xrange(trial.NUM_COINS):            # grab frequency            v_i = coin().frequency            # hold on to pocket minimum frequency            if v_i < v_min:                v_min = v_i            # get random frequency            if i == trial.C_RAND_IDX:                v_rand = v_i            # get first            if i == 0:                v_first = v_i                   # some error checking to make sure they don't        # still have their default values at this point        # would be great            return {'rand': v_rand, 'first': v_first, 'min': v_min}   data = DataFrame([trial().results for i in xrange(100000)])
Generating a PANDAS DataFrame of simulated coin tosses
python;performance;python 2.7;simulation;pandas