码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算效能分析

时间:2018-04-18 22:28:06      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:bubuko   style   height   str   choice   提交   port   https   计算   

 

Github项目地址:https://github.com/lsk-lsk/Python

估计将在程序的各个模块的开发上耗费的时间:

 

 

预测时间(分钟)

Planning

计划

5

Estimate

估计这个任务需要多少时间

180

Development

开发

15

Analysis

需求分析

15

Design Spec

生成设计文档

5

Design Review

设计复审(和同事审核设计文档)

5

Coding Standerd

代码规范(为目前的开发制定合适的规范)

5

Design

具体设计

5

Coding

具体编码

60

Code Review

代码复审

20

Text

测试(自测,修改代码,提交修改)

10

Reporting

报告

10

Text Report

测试报告

10

Size Measurement

计算工作量

5

Postmortem & Process Improvement Plan

事后总结,并提出过程改进计划

10

 解题思路描述:

(1)为了便于测试,随机自动生成小学四则运算题目,用到random库

(2)选择效能分析工具cProfile和time进行测试

设计实现过程:使用了3个函数,分别为test1(),test2(),cal(),其中test1(),test2()用来生成四则运算题目,cal()用来计算结果并判断是否正确

代码说明:

import cProfile
import random
import time
start = time.time()

def test1(t):
s1 = random.randint(1,10)
s2 = random.randint(1,10)
s3 = random.choice([‘+‘,‘-‘,‘*‘,‘/‘])
cal(s1,s2,s3,t)

def test2(t):
s1 = random.randint(1,10)
s2 = random.randint(s1,11)
s3 = random.randint(1,10)
s4 = random.randint(s3,11)
s5 = random.choice([‘+‘,‘-‘])
sr = "第" + str(t) + "题:" + str(s1) + ‘÷‘+ str(s2) + s5+str(s3) + ‘÷‘+ str(s4) + ‘=‘
l1.append(sr)
if s5 == ‘+‘:
l2.append(s1 / s2 + s3 / s4)
else:
if s1 / s2 - s3 / s4 > 0:
l2.append(s1 / s2 - s3 / s4)
else:
sr = "第" + str(t) +"题:" + str(s3) + ‘÷‘+ str(s4) + s5 + str(s1) + ‘÷‘ + str(s2) + ‘=‘
l2.append(s3 / s4 - s1 /s2)
def cal(s1,s2,s3,t):
sr = "第" + str(t) + "题:" + str(s1) + s3 + str(s2) + ‘=‘
if s3 == ‘+‘:
l2.append(s1 + s2)
elif s3 == ‘-‘:
if s1 >= s2:
l2.append(s1 - s2)
else:
sr = "第" + str(t) + "题:" + str(s2) + s3 + str(s1) + ‘=‘
l2.append(s2 - s1)
elif s3 == ‘*‘:
sr = "第" + str(t) + "题:" + str(s1) + ‘x‘ + str(s2) + ‘=‘
l2.append(s1 * s2)
elif s3 == ‘/‘:
sr = "第" + str(t) + "题:" + str(s1) + ‘÷‘ + str(s2) + ‘=‘
l2.append(s1 / s2)
l1.append(sr)
t = 1
l1 = []
l2 = []

while t <= 10:
if t <= 5:
test1(t)
elif t <= 10:
test2(t)
print(l1[t - 1])
n=eval(input())
if l2[t -1] == n:
print("回答正确!")
else:
print("回答错误!")
t += 1

cProfile.run(‘cal‘)
cProfile.run(‘test1‘)
cProfile.run(‘test2‘)
end=time.time()
print(end-start)


测试运行:

技术分享图片

技术分享图片

性能分析:

技术分享图片

技术分享图片

 

 实际花费时间:

 

 

 

实际时间(分钟)

nning

计划

10

Estimate

估计这个任务需要多少时间

205

Development

开发

12

Analysis

需求分析

18

Design Spec

生成设计文档

5

Design Review

设计复审(和同事审核设计文档)

5

Coding Standerd

代码规范(为目前的开发制定合适的规范)

5

Design

具体设计

5

Coding

具体编码

80

Code Review

代码复审

20

Text

测试(自测,修改代码,提交修改)

5

Reporting

报告

15

Text Report

测试报告

10

Size Measurement

计算工作量

5

Postmortem & Process Improvement Plan

事后总结,并提出过程改进计划

10

四则运算效能分析

标签:bubuko   style   height   str   choice   提交   port   https   计算   

原文地址:https://www.cnblogs.com/junkunjuan/p/8877926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!