coldfusion_ColdFusion函数和运算符上的运行性能指标

本文通过实际测试,对比了ColdFusion中Evaluate()函数与数组表示法的性能,结果显示两者在毫秒级上的差异微乎其微,对于中小型应用,使用Evaluate()不会造成显著的系统瓶颈。

coldfusion

…posted by davidjmedlock:

…由 davidjmedlock 发布

Have you ever noticed developers making statements about how well various operators and functions perform when compared with other functions and operators? For example, how well does perform when compared to ? Is there really a significant difference?

您是否曾经注意到开发人员声明各种运算符和功能与其他函数和运算符相比的性能如何? 例如,效果如何 与 ? 真的有很大的不同吗?

Well, in my recent article on queries, I used a block of code that output the columns in a query in a table and then output the values below that. In that query I used the Evaluate() function to display the values of the columns. One eagle-eyed reader pointed out to me that using array notation is preferable to the Evaluate function and that Evaluate should be avoided in any situation if at all possible. Here’s the code block I used:

好吧,在我最近的有关查询的文章中,我使用了一段代码,该代码块将查询中的列输出到表中,然后输出该值以下的值。 在该查询中,我使用了Evaluate()函数来显示列的值。 一位老鹰眼的读者向我指出,使用数组表示法比使用Evaluate函数更可取,并且在任何情况下都应尽可能避免使用Evaluate。 这是我使用的代码块:

#column#
#Evaluate(column)#
#柱#
#Evaluate(column)#

The suggestion was that instead of using Evaluate(column), I should have used GetUsers

的建议是,我应该使用GetUsers而不是使用Evaluate(column)

Now, I’m not offended by any remarks such as this at all. I enjoy seeing how other people code their applications and, hey, if it speeds up my app to use a different method, I’m all ears! But sometimes developers take things to extremes. I decided to do some research to find out if useing Evaluate(column) really was faster than GetUsers

现在,我完全不会受到任何这样的言论的​​冒犯。 我很高兴看到其他人如何编码他们的应用程序,并且,嘿,如果它可以加快我的应用程序使用其他方法的速度,我将非常高兴! 但是有时开发人员会将事情推向极端。 我决定进行一些研究,以确定使用Evaluate(column)是否真的比GetUsers更快

This experiment was not entirely comprehensive and I invite everyone to try this experiment out (on a development machine, NOT a live server!) to with different variables to see what results you get.

该实验并不完全全面,我邀请每个人(在开发机上,而不是在线服务器上)尝试该实验,并使用不同的变量来查看获得的结果。

First, here is the code I used:

首先,这是我使用的代码:

// this simply sets up the testing query qry = QueryNew("col1,col2"); for (i = 1; i lte 10; i = i + 1) { QueryAddRow(qry, 1); QuerySetCell(qry, "col1", i * 2, qry.RecordCount); QuerySetCell(qry, "col2", i * 3, qry.RecordCount); }

//这只是设置测试查询qry = QueryNew(“ col1,col2”); 对于(i = 1; ilte 10; i = i + 1){QueryAddRow(qry,1); QuerySetCell(qry,“ col1”,i * 2,qry.RecordCount); QuerySetCell(qry,“ col2”,i * 3,qry.RecordCount); }

Entire Process Time: #endTest# (ms) Total Looping Time: #TotalTime# (ms) Average Looping Time: #AvgTime#

整个处理时间:#endTest#(ms)总循环时间:#TotalTime#(ms)平均循环时间:#AvgTime#

I created a query that was 2 columns by 10 rows. I then looped over the query 20,000 times. Inside the query loop, I looped over the qry.ColumnList variable and set a variable called temp to the value of the current column in the current row.

我创建了一个2列乘10行的查询。 然后,我遍历了该查询20,000次。 在查询循环中,我遍历了qry.ColumnList变量,并将一个名为temp的变量设置为当前行中当前列的值。

Notice that I ran this test 20 different times and then I changed the:

请注意,我对该测试运行了20次不同的时间,然后更改了:

to:

至:

and then ran it another 20 times. I recorded the total amount of time it took for the 20,000 iterations, the average time for each iteration, and the total time it took to process the entire page. All times are in millseconds. To make a long story a little bit shorter, the average evaluation time using the array notation was .231 milliseconds. (Yes, that’s a very small number.) The average evaluation time using Evaluate() was .228 milliseconds. That’s an even smaller number. If you look at the data, all the numbers using Evaluate() were smaller. All the other code remained exactly the same.

然后又跑了20次 我记录了20,000次迭代所花费的总时间,每次迭代的平均时间以及处理整个页面所花费的总时间。 所有时间均为毫秒。 长话短说,使用数组表示法的平均评估时间为0.231毫秒。 (是的,这是一个很小的数字。)使用Evaluate()的平均评估时间为0.228毫秒。 这个数字甚至更少。 如果查看数据,则使用Evaluate()的所有数字都较小。 所有其他代码保持完全相同。

I did not restart my server in between these tests, which may have altered the results a bit due to recompiling and initializing everything. I doubt it would have has a huge effect on the results, though. And in a live environment, you don’t restart the server every time you run a report or load a form, etc.

在这两次测试之间,我没有重新启动服务器,这可能是由于重新编译和初始化所有内容而导致结果有所改变。 我怀疑这会对结果产生巨大影响。 在实时环境中,您不必每次运行报表或加载表单等时都重新启动服务器。

I’m going to run some more tests at a later point in time to see what results I get. I’ll increase the iterations to 100,000 and run it 50 times. (When I get the time for that… It will probably take a good 45 seconds or so to run each time.)

我将在稍后的时间运行更多测试,以查看得到的结果。 我将迭代次数增加到100,000,然后运行50次。 (当我有时间的时候……每次可能要花大约45秒左右的时间。)

I guess my point here is that for a small to medium sized application, using Evaluate() is not going to cause a huge bottleneck in your system. Yes, there are usually other ways around it and if you don’t like using it, then find another way around it. And this is only one scenario using the Evaluate() function. There are countless others and in other situations Evaluate() may not perform well at all.

我想我的意思是,对于中小型应用程序,使用Evaluate()不会在您的系统中造成巨大的瓶颈。 是的,通常还有其他解决方法,如果您不喜欢使用它,则可以找到其他解决方法。 这只是使用Evaluate()函数的一种情况。 还有无数其他情况,在其他情况下,Evaluate()可能根本无法表现良好。

Here are a few links about CF performance you may find interesting:

以下是一些有关CF性能的链接,您可能会发现它们很有趣:

http://www.markme.com/cantrell/archives/003088.cfm – CFSCRIPT performance

http://www.markme.com/cantrell/archives/003088.cfm – CFSCRIPT性能

http://www.findarticles.com/cf_dls/m0MLU/11_4/94550933/p1/article.jhtml – CFIF performance

http://www.findarticles.com/cf_dls/m0MLU/11_4/94550933/p1/article.jhtml – CFIF性能

Download the Excel spreadsheet with performance data

下载包含性能数据的Excel电子表格

翻译自: https://www.sitepoint.com/running-performance-metrics-on-coldfusion-functions-and-operators/

coldfusion

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值