局部变量与全局变量的效率测试


#!/usr/bin/env python
#-*- coding:utf-8 -*-
import math
import time

def test01():
    start=time.time()
    for i in range(1000000):
        math.sqrt(30)
    end=time.time()
    print("耗时{0}".format((end-start)))

def test02():
    b=math.sqrt
    Start=time.time()
    for i in range(1000000):
        b(30)
    end=time.time()
    print("耗时{0}".format((end-Start)))


test01()
test02()

 

相关