我有一个小 Lua 脚本要在 Redis 中运行,我对获取执行时间感兴趣。
由于 Redis 的性质及其 Lua 实现,我无法在脚本的开始/返回点使用 TIME 函数,并将此信息包含在返回中进行处理(请参阅http://redis.io/commands/eval -作为纯函数的脚本)。这会导致错误:(error) ERR Error running script (call to f_a49ed2fea72f1f529843d6024d1515e76e69bcbd): Write commands not allowed after non deterministic commands
我已经搜索了可以执行的函数/调用,该函数/调用将返回上次运行脚本的执行时间,但尚未找到任何内容。
我正在使用 PHP 和 Predis 库。虽然我可以从 PHP 端检查执行时间,但我希望消除传输开销并找出 Lua 脚本将阻止对数据库的访问多长时间。如果我不需要更改 Redis 中存储的任何数据,我已经成功返回了时间,这些时间大约是 PHP 报告时间的 1/10。
如何确定 Redis 中 Lua 脚本的执行时间,而不是通过 PHP?
如何使用c#执行方法时,如何记录方法的持续时间,时间开始和结束时间?
例如,我点击一个按钮,它会做一些事情.一旦开始,我将获得开始时间,然后当执行完成时,我将得到时间结束以及完成所需的持续时间.
这是我关于堆栈溢出的上一个问题的后续问题。我会将脚本缩减为基本部分,但如果这样认为,了解脚本的作用可能会有所帮助,您可以研究其他问题。
#!/usr/bin/env bash
set -eu -o pipefail
declare -a framelist
#Print all results
function output_values() {
echo "Results!";
}
#parsing information from stdin
function parser () {
while read tc;
do
if [ -z "$tc" ]; then
continue
fi
#Evaluation and saving result to array
echo $result_value;
framelist+=($result_value);
if (( <<some abort condition>> )); then
exec 0>&-
echo "Last result: $result_value";
return 0
fi
done
}
some_command_writing_to_stdout | parser $2;
output_values;
Run Code Online (Sandbox Code Playgroud)
该脚本执行命令并将输出通过管道传输到我的本地函数,该函数最终按echo "Last result: $result_value";预期返回该行的结果。此后,它将终止提供在此函数中解析的数据的命令 - 这也有效。 …
我在 python 3.6 中导入了unittest,并像这样使用它:
class TestFunc(unittest.TestCase):
def test_half(self):
pass
def test_merge(self):
pass
def test_decrypt(self):
pass
def test_rank(self):
pass
if __name__ == "__main__":
print("printing before calling unittest")
unittest.main()
print("printing after calling unittest")
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
printing before calling unittest
....
----------------------------------------------------------------------
Ran 4 tests in 0.001s
OK
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)
对printie的第二次调用print("printing after calling unittest")不会执行。为什么单元测试后我什么也做不了?测试后如何继续使用代码?
在powershell中,与在 中一样cmd,您必须键入文件的路径,包括文件本身,或者如果您与文件所在的位置相同,则只需键入文件名,下面显示了每种情况的示例:
# if the file is a different location
[Path to the file]\[fileName]
# if the file is in the same location
.\[fileName]
Run Code Online (Sandbox Code Playgroud)
我想要做的是将文件的路径分配给一个变量,当我想打开文件时只需键入变量名称,如下所示:
$path = [fileLocation + fileName]
Run Code Online (Sandbox Code Playgroud)
但是,问题是,当我键入变量时,PowerShell 会返回 的字符串值$path,因此,如何通过将文件的路径分配给变量来启动文件?
每次我在执行 SQL 查询时都会得到相同的执行时间。如果 SQL 查询运行多次,是否有机会始终获得相同的执行时间?
我想根据完成时执行的循环和条件来获取 python 函数的执行跟踪。但是,我想在不使用附加参数检测原始 python 函数的情况下执行此操作。例如:
def foo(a: int, b: int):
while a:
a = do_something()
if b:
a = do_something()
if __name__ == "__main__":
foo(a, b)
Run Code Online (Sandbox Code Playgroud)
在执行之后,foo()我想要一个类似的执行跟踪:
[while: true, if:false, while: true, if: true, while: false, ...]它记录了代码中条件评估的序列。有没有办法为任意的python函数自动获取这些信息?
我了解“覆盖率”python 模块返回“分支覆盖率”信息。但我不确定如何在这种情况下使用它?
当我使用console.time和console.timeEnd来测量 JavaScript 中函数或代码片段的执行速度时,它会将其打印到控制台:
timer: 14657.580078125 ms
如何将其四舍五入到最接近的整数或其他数字?我查看了这两个函数的文档,但都没有告诉我如何执行此操作。
我有一些像这样的ruby代码:
result1 = function_1(params)
result2 = function_2(params)
result3 = function_3(params)
Run Code Online (Sandbox Code Playgroud)
但有时其中一些可能需要花费太多时间才能工作(此功能取决于互联网连接速度).如果需要超过5秒钟,我需要终止函数的执行.我应该如何用ruby-way做到这一点?
execution ×10
c# ×2
python ×2
time ×2
unit-testing ×2
bash ×1
console ×1
duration ×1
javascript ×1
linux ×1
lua ×1
performance ×1
powershell ×1
python-3.x ×1
redis ×1
ruby ×1
shell ×1
specflow ×1
sql-server ×1
stdout ×1
terminate ×1
timeout ×1
timer ×1