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

#!/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()

 

 

 

 

 

posted @ 2021-04-24 21:16  614_四爷  阅读(97)  评论(0编辑  收藏  举报