我想计算java、python、javascript等各种语言的代码执行时间。如何获取这些代码的执行时间。python 包或任何其他工具中是否有任何工具可以通过传递文件(任何文件 java 或 python)路径来计算执行时间。请分享您的建议。
我知道通过在 python 代码中使用 time 模块来获取执行时间。如何在python中执行Javascript和java代码并获取常用函数的执行时间。
我在下面的方法中尝试过。
import time
def get_exectime(file_path): # pass path of any file python,java,javascript, html, shell
start_time=time.time()
# execute the file given here. How to execute all file types here?
end_time=time.time()
exec_time=end_time-start_time
print(exec_time)
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以实现这一目标?
我正在使用OpenCV库进行一些图像处理,我发现处理图像所需的时间取决于我在图像处理之间让我的线程进入睡眠状态的时间.我测量了程序的几个部分的执行时间,并且我发现函数cv :: remap()似乎执行速度慢两倍,如果我让我的线程睡眠超过一段时间.
下面是显示奇怪行为的最小代码段.我测量执行cv :: remap()函数所花费的时间,然后我将我的威胁发送到sleep_time中设置的毫秒数.
#include <opencv2/imgproc.hpp>
#include <thread>
#include <iostream>
int main(int argc, char **argv) {
cv::Mat src = ... // Init
cv::Mat dst = ... // Init
cv::Mat1f map_x = ... // Init;
cv::Mat1f map_y = ... // Init;
for (int i = 0; i < 5; i++) {
auto t1 = std::chrono::system_clock::now();
cv::remap(src, dst, map_x, map_y, cv::INTER_NEAREST, cv::BORDER_CONSTANT, 0);
auto t2 = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_time = t2 - …Run Code Online (Sandbox Code Playgroud) 我有一段代码对执行速度的要求高于其他任何东西。通过使用high_resolution_clock()from,std::chrono我发现这个 switch() 到 if-else() 梯子占用了我 70% 以上的执行时间。有什么办法可以加快这个速度吗?
我在编译过程中使用了gcc优化-O3。
我研究了一个类似的问题:If elseladder optimization但我不能使用 return 语句,因为它会退出我不能的外循环。
switch(RPL_OPTION) {
case 0:
for(int k = 0; k < WINDOW_SIZE; k++) {
if(ans[k] >= upper_th) {
//Increasing flag counter
flag_count++;
//Adding the filtered value to the output vector
filtered_output.push_back(ans[k]);
flag_output.push_back(1);
} else if(ans[k] < lower_th) {
//Increasing flag counter
flag_count++;
//Adding the filtered value to the output vector
filtered_output.push_back(ans[k]);
flag_output.push_back(1);
} else {
//Adding the filtered …Run Code Online (Sandbox Code Playgroud) 我for在 Delphi 中编写了一个简单的循环并将其翻译为 Julia。与 Julia 程序相比,Delphi 程序的执行时间简直可怜:Julia 快了 7 倍 -查看程序和结果。
我试图弄清楚这是如何可能的,因为 Delphi 应该是地球上最快的语言之一!
我想将 Julia 生成的 ASM 代码与 Delphi 生成的 ASM 代码进行比较。在 Delphi 中,我只需单击一下即可获取该代码。在哪里可以看到 Julia 中特定函数的 ASM 代码?
using BenchmarkTools
println("----------- Test for loops")
# test for loops
function for_fun(a)
total = 0
big = 0
small = 0
for i in 1:a
total += 1
if i > 500000
big += 1
else
small += 1
end
end
return (total, small, big)
end
res_for …Run Code Online (Sandbox Code Playgroud) 我需要将函数的执行时间(以毫秒为单位)存储在 sql 字段中。我应该使用什么数据类型?
有没有比clock()Windows上的功能更好的功能或方法来衡量时间?我有一个简短的操作,当我尝试clock()或gettickcount()它说它花了0.0秒.我需要一种方法来测量毫秒或纳秒.
在SAS中是否可以创建进度条,该进度条能够计算执行程序的剩余百分比/时间?
我在共享托管平台上,并希望限制我的应用程序中的查询,以便如果总执行时间超过一定量的可变时间段,那么我可以让应用程序冷却,然后稍后恢复.
要做到这一点,我想知道我的每个查询实时采取多长时间并在应用程序中管理它,而不是通过外部进行分析.
我已经在PHP中看到了在查询之前和之后记录时间的示例(甚至phpMyAdmin都这样做),但这在NodeJS或异步运行查询的任何内容中都不起作用.
所以问题是:我如何在NodeJS中获取查询的实际执行时间?
作为参考,我使用这个模块来查询MySQL数据库:https://github.com/felixge/node-mysql/
在C++中执行程序(精确到毫秒)后,最简单,最干净的方法是什么?
我正在制作一个波浪干涉模拟器,用C++ 生成Lissajous曲线.它需要自执行程序(精度至少为毫秒)起的时间才能运行.经过一些研究后,我似乎无法找到任何干净简单的方法.
所有<chrono>功能对我来说都很困惑.Stack Overflow上的类似问题似乎是无关的,令我感到困惑(对我而言)或不适用于我的情况.我尝试使用函数<time.h>,但发现它们只有精度达到秒.
我正在运行Windows 7 x64.该程序不需要独立于平台,因为它是供个人使用的.任何帮助是极大的赞赏.
谢谢!
我很难理解为什么这个代码以英特尔编译器12以极快的速度运行,并且使用英特尔编译器16真的变慢了
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
int i,t;
int n=10000000;
int T=1000;
time_t t1,t2;
// double A[n],B[n],C[n];
double *A = (double*) malloc (sizeof(double)*n);
double *B = (double*) malloc (sizeof(double)*n);
double *C = (double*) malloc (sizeof(double)*n);
for (i=0;i<n;i++)
{
A[i]=1.0;
B[i]=2.0;
}
t1=clock();
for (t=0;t<T;t++)
for (i=0;i<n;i++)
C[i]=A[i]*B[i];
t2=clock();
double sum=0.0;
for (i=0;i<n;i++) sum += C[i];
printf("sum %f\n",sum);
printf("time %f\n",(double)(t2-t1)/CLOCKS_PER_SEC);
}
Run Code Online (Sandbox Code Playgroud)
makefile:icc -O2 -o array array.c
execution-time ×10
c++ ×3
c ×2
optimization ×2
performance ×2
delphi ×1
elapsedtime ×1
icc ×1
if-statement ×1
julia ×1
mysql ×1
node-mysql ×1
node.js ×1
opencv ×1
progress-bar ×1
python ×1
remap ×1
sas ×1
sql ×1
time ×1
types ×1
windows ×1