Beispiel #1
0
def pi(n):                                          #4
    """
    Calculation of pi with Monte Carlo Simulation.

    n is the number of iterations.    
    """
    return plain_pi.piPlain(n)
Beispiel #2
0
def handlePiPost(request):                          #3
    n = int(float(request.args['n'][0]))            #4
    start = timeit.default_timer()
    pi = plain_pi.piPlain(n)                        #5
    duration = timeit.default_timer() - start 
    request.write('''
        <html>
        <head><title>Pi with Twisted</title></head>
        <body>
        <h1>
        Twisted - Result of Monte Carlo Calculation of Pi
        </h1>
        <table>
        <tr>
        <td>Number of iterations</td>
        <td>%d</td>
        </tr>
        <tr>
        <td>Pi by Monte Carlo Method</td>
        <td>%15.12f </td>
        </tr>
        <tr>
        <td>Exact pi</td>
        <td>%15.12f </td>
        </tr>
        <td>Calculation time</td>
        <td>%15.3f seconds</td>
        </tr>
        </table>
        </body>
        </html>
    ''' %(n, pi, math.pi, duration))                #6
    request.finish()
Beispiel #3
0
 def xmlrpc_pi(self, n):                         #4
     return plain_pi.piPlain(n)
Beispiel #4
0
 def remote_pi(self, n):                         #3
     return plain_pi.piPlain(n)
Beispiel #5
0
<td>%15.12f </td>
</tr>
<tr>
<td>Exact pi</td>
<td>%15.12f </td>
</tr>
<td>Calculation time</td>
<td>%15.3f seconds</td>
</tr>
</tr>
<td>Calculation parallel</td>
<td>%s</td>
</tr>
</table>
</body>
</html>
'''


start = timeit.default_timer()

if parallel == 'no':
    pi = plain_pi.piPlain(n)                    #8
else:
    pi_maker = pithreaded.PiMaker(n, 2)
    pi = pi_maker.calculate_pi(pithreaded.ThreadedPi)
	
duration = timeit.default_timer() - start

print template %(n, pi, math.pi, duration, parallel)  #9
Beispiel #6
0
 def soap_pi(self, n):                       #3
     return plain_pi.piPlain(n)