ASP.NET指定变量数据类型,速度提高了100倍

ASP.NET指定变量数据类型,速度提高了100倍由自动编程人工智能 发表在专区

10亿次求余数为0的计算:

ASP运行速度130秒左右

' ASP.NET Dim i, c, max '如果不指定数据类型,运行要120秒左右

Dim i, c, max As Integer '指定数据类型,运行速度2秒

  1. 下面是ASP.NET代码:


强类型,指定变量类型

测试1亿次13秒左右。测试10亿次下面的MAX要乘1000

打开网站方法:http://localhost:8080/ASP_modtest.asp


ASP .NET:

<%Server.ScriptTimeout = 500%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
</head>
 
<body>
强类型,指定变量类型<br>
测试1亿次13秒左右。测试10亿次下面的MAX要乘1000<br>
打开网站方法:<a href='http://localhost:8080/ASP_modtest.asp'>http://localhost:8080/ASP_modtest.asp</a> <br>
<%

dim a  as DateTime
a  = DateTime.Now 
 
Dim i, c, max As Integer
max = 1000000 * 1000
c = 0
For i = 1 To max
    If i Mod 7 = 0 Then c = c + 1
Next

dim b as DateTime
b =DateTime.Now 
Dim span3 As TimeSpan = b.Subtract(a ) 

response.write ("时间差(时、分、秒):" & span3.tostring() & "<br>")
 response.write (a.tostring()+"<br>")
response.write (b.tostring()+"<br>")
%>

</body></html>

asp运行速度测试


测试1亿次13秒左右。测试10亿次下面的MAX要乘1000

打开网站方法:http://localhost:8080/ASP_modtest.asp

<%Server.ScriptTimeout = 500%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>asp运行速度测试</title>
</head>
 
<body>
测试1亿次13秒左右。测试10亿次下面的MAX要乘1000<br>
打开网站方法:<a href='http://localhost:8080/ASP_modtest.asp'>http://localhost:8080/ASP_modtest.asp</a> <br>
<%
'i5 8600k,139秒
dim a,b
a=timer
dim i,max
dim c 
max=1000000*1000
c=0
for i=1 to max
if i mod 7=0 then c=c+1
next
b=timer
response.write "测试次数:" & max & ",找到7的倍数个数:" & c & vbcrlf & "用时:" & (b-a) & "秒<br><br>"
%>

</body></html>

猜你喜欢

转载自blog.csdn.net/xiaoyao961/article/details/132395758