测量Spreadsheet的内置函数的执行时间 [英] Measurement of execution time of built-in functions for Spreadsheet
问题描述
是否有方法来测量Spreadsheet的内置函数完成时的执行时间?当我使用多个内置函数(例如,IMPORTHTML和IMPORTXML)时,如果我知道平均执行时间,则可以轻松使用和设计数据表。
function myFunction(){
var start = new日期();
//做某事
var end = new Date();
var executiontime = end - start;
}
非常感谢您的宝贵时间和建议。
遗憾的是,没有用于检索内置函数执行时间的测量工具。这已经被@Rubén评论了。所以我想到了解决方法。如何解决以下问题?
流程:
- 将值导入细胞。值是好的,因为这被用作触发器。请自己做。
- 自定义函数不能使用
setValue()
。所以我用onEdit()
。
- 自定义函数不能使用
-
func1 ()
导入一个公式,您希望通过触发器启动的脚本来测量执行时间。func2 ,设置公式后,测量开始。内置功能完成时的确认使用循环进行。
- 通过测量
getValue()
的每次调用成本,发现它是关于0.0003秒。所以我认为可以使用它。
- 通过测量
- 测量结果可以在Stackdriver中以毫秒显示。
$ b示例脚本:
函数func1(范围,公式){
range.setFormula(公式);
函数func2(范围){
var d = range.getValue();
while(r == d){
var r = range.getValue();
function onEdit(){
var formula ='###内置函数###'; //请设置您想要测量执行时间的内置函数。
var label =内置函数的执行时间。;
var ss = SpreadsheetApp.getActiveSheet();
var cell = ss.getActiveCell();
var range = ss.getRange(cell.getRow(),cell.getColumn());
func1(范围,公式);
console.time(label);
func2(范围);
console.timeEnd(label);
}
注意:
- 测量很长时间的内置函数时,可能会在
getValue()
处发生错误。
- 在我的环境中,10秒的内置函数可以正常工作。
如果这对您有用,我很高兴。
Are there methods to measure the execution time when built-in functions completed for Spreadsheet? When I use several built-in functions (For example, IMPORTHTML and IMPORTXML), if I know the average execution-time, it is easy for me to use and design data sheet.
I measure it of custom functions using this script.
function myFunction() { var start = new Date(); // do something var end = new Date(); var executiontime = end - start; }
Thank you so much for your time and advices.
解决方案Unfortunately, there are not measurement tools for retrieving the execution time of built-in functions. This has already been commented by @Rubén. So I thought of about the workarounds. How about the following workaround?
Flow :
- Import a value to a cell. The value is anything good, because this is used as a trigger. Please do this by yourself.
- Custom functions cannot use
setValue()
. So I usedonEdit()
.
- Custom functions cannot use
func1()
imports a formula that you want to measure the execution time by the script launched by the trigger.- At
func2()
, after set the formula, the measurement is started. The confirmation when built-in function was completed is carried out using loop.- By measuring the cost per one call for
getValue()
, it was found that that was about 0.0003 s. So I thought that this can be used.
- By measuring the cost per one call for
- The result of measurement can be seen at Stackdriver as milliseconds.
Sample script :
function func1(range, formula){ range.setFormula(formula); } function func2(range){ var d = range.getValue(); while (r == d) { var r = range.getValue(); } } function onEdit(){ var formula = '### Built-in function ###'; // Please set the built-in function you want to measure the execution time. var label = "Execution time for built-in functions."; var ss = SpreadsheetApp.getActiveSheet(); var cell = ss.getActiveCell(); var range = ss.getRange(cell.getRow(), cell.getColumn()); func1(range, formula); console.time(label); func2(range); console.timeEnd(label); }
Note :
- When built-in functions with very long time is measured, an error may occur at
getValue()
.- In my environment, the built-in function for 10 seconds worked fine.
If this was useful for you, I'm glad.
这篇关于测量Spreadsheet的内置函数的执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 测量很长时间的内置函数时,可能会在