Book Image

Python for Finance

By : Yuxing Yan
Book Image

Python for Finance

By: Yuxing Yan

Overview of this book

Table of Contents (20 chapters)
Python for Finance
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Measuring efficiency by time spent in finishing a program


The following program measures how much time, in seconds, is required to finish a program. The function used is time.clock():

import time
start = time.clock()
n=10000000
for i in range(1,n):
    k=i+i+2
diff= (time.clock() - start)
print round(diff,2)

The total time we need to finish the previous meaningless loop is about 1.59 seconds.