pprocess

examples/simple.py

143:2f919af8a8bc
2008-06-02 paulb [project @ 2008-06-02 19:33:57 by paulb] Updated release information.
     1 #!/usr/bin/env python     2      3 """     4 A simple example of a computation performed sequentially.     5 """     6      7 import time     8 #import random     9     10 # Array size.    11     12 N = 10    13 delay = 1    14     15 # Main program.    16     17 if __name__ == "__main__":    18     19     t = time.time()    20     21     # Initialise an array.    22     23     results = [0] * N * N    24     25     # Perform the work.    26     27     print "Calculating..."    28     for i in range(0, N):    29         for j in range(0, N):    30             #time.sleep(delay * random.random())    31             time.sleep(delay)    32             results[i*N+j] = i * N + j    33     34     # Show the results.    35     36     for i in range(0, N):    37         for result in results[i*N:i*N+N]:    38             print result,    39         print    40     41     print "Time taken:", time.time() - t    42     43 # vim: tabstop=4 expandtab shiftwidth=4