我看到每个人都建议使用一个变量,例如
$start_time = microtime(TRUE);
Run Code Online (Sandbox Code Playgroud)
在脚本的顶部,然后在最后一行我们做:
$process_time = microtime(TRUE) - $start_time;
Run Code Online (Sandbox Code Playgroud)
我的问题是,我们能否可靠地使用$_SERVER['REQUEST_TIME_FLOAT']和跳过 $start_time ?如果是这样,为什么每个人仍然建议在顶部使用 $start_time ?
我的意思的例子:
<?php
// No need for $start_time...
// All the stuff we do to have the benchmark at the end
// Only this line needed to display execution time
echo "Processed in: ". bcsub(microtime(TRUE), "{$_SERVER['REQUEST_TIME_FLOAT']}", 4);
?>
Run Code Online (Sandbox Code Playgroud) 这是我的观点:
def post_detail(request, year, month, day, slug):
post = get_object_or_404(models.Post, slug=slug, status='published',
publish__year=year, publish__month=month,
publish__day=day)
comment_form = forms.CommentForm()
comments = post.comments.filter(active=True)
context = {
'comments': comments,
'post': post,
'comment_form': comment_form,
}
return render(request, 'blog/post_detail.html', context)
Run Code Online (Sandbox Code Playgroud)
有什么方法可以计算 Django 中的执行时间吗?
我的一个包含 7 个空测试的测试文件需要5 秒多的时间才能开始运行。我flutter test在 VS Code 中使用了这两种方法以及 Dart 测试运行器,它们花费的时间大约相同。
我的整个测试套件包含约 150 个测试,需要30 秒以上才能完成,因为每个测试文件需要 3-7 秒才能开始运行。
launch.json(用于 Dart 测试运行程序) {
"name": "Dart: Run all tests",
"type": "dart",
"request": "launch",
"program": "./test/"
},
Run Code Online (Sandbox Code Playgroud)
定时测试运行:
00:05 +1 -7: Some tests failed.
real 0m9.532s
user 0m0.075s
sys 0m0.138s
Run Code Online (Sandbox Code Playgroud)
我正在使用嵌套组块,但我不认为这会导致如此巨大的延迟,从而使 TDD 极其缓慢
代码示例部分00:05 +1 -7: Some tests failed.
real 0m9.532s
user 0m0.075s
sys 0m0.138s
Run Code Online (Sandbox Code Playgroud)
我什至尝试过分别测试和组合测试两个空的示例测试文件(参见下面的代码),单独运行都需要 4 秒以上的时间。如果我将两个测试文件合并为一个文件,则执行时间几乎与仅一个测试相同。
问题似乎在于启动每个测试文件,而不是测试本身。
void main() {
group('AuthCubit:', () …Run Code Online (Sandbox Code Playgroud) optimization unit-testing execution-time flutter-test dart-test
我有一个PHP页面,我每分钟都通过CRON作业运行.
我已经运行了很长一段时间但突然间它开始抛出这些错误:
Maximum execution time of 30 seconds exceeded in /home2/sharingi/public_html/scrape/functions.php on line 84
Run Code Online (Sandbox Code Playgroud)
行号将随每个错误而变化,范围从第70行到90年代.
这是第0-95行的代码
function crawl_page( $base_url, $target_url, $userAgent, $links)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops
$html = curl_exec($ch);
if (!$html)
{
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
//exit;
}
//
// load scrapped …Run Code Online (Sandbox Code Playgroud) 我正在用C++实现一个检查系统.它使用不同的测试运行可执行文件.如果解决方案不正确,可能需要永远完成某些硬测试.这就是为什么我想将执行时间限制为5秒.
我正在使用system()函数来运行可执行文件:
system("./solution");
Run Code Online (Sandbox Code Playgroud)
.NET有一个很棒的WaitForExit()方法,那么本机C++呢?我也使用Qt,因此欢迎基于Qt的解决方案.
那么有没有办法将外部进程的执行时间限制为5秒?
谢谢
java中是否有命令来测量执行时间?
就像是
System.out.println(execution.time);
Run Code Online (Sandbox Code Playgroud)
在代码的最后.
假设我有"堆排序"方法,其复杂时间为O(nlogn).当我在1000000输入上测量此方法的执行时间时,我得到了0.375770669秒.如何从理论上计算出该方法的执行时间?
在我的应用程序中,我想看看Windows 7是否被激活.要清楚,我不想检查窗户是否是正品.我使用下面的代码,在这里找到http://www.dreamincode.net/forums/topic/166690-wmi-softwarelicensingproduct/
执行查询所需的时间约为5-10秒.反正有没有减少所需的时间?或者另一种检查winows 7是否被激活的方法?
public string VistaOrNewerStatus(){
string status = string.Empty;
string computer = ".";
try
{
//set the scope of this search
ManagementScope scope = new ManagementScope(@"\\" + computer + @"\root\cimv2");
//connect to the machine
scope.Connect();
//use a SelectQuery to tell what we're searching in
SelectQuery searchQuery = new SelectQuery("SELECT * FROM SoftwareLicensingProduct");
//set the search up
ManagementObjectSearcher searcherObj = new ManagementObjectSearcher(scope, searchQuery);
//get the results into a collection
using (ManagementObjectCollection obj = searcherObj.Get())
{
MessageBox.Show(obj.Count.ToString());
//now loop …Run Code Online (Sandbox Code Playgroud) 我注意到我的c#app有点不寻常.我第一次执行某些代码比后续执行需要更长的时间.任何人都可以向我解释为什么会这样吗?
通过我下面的简单测试应用程序甚至可以看到它的初始输出大约为13,后续输出大约为3.
Stopwatch sw;
int count = 0;
private void Window_KeyUp(object sender, KeyEventArgs e)
{
RunTest();
}
private void RunTest()
{
sw = Stopwatch.StartNew();
count = 0;
for (int i = 0; i < 100; i++)
{
count++;
}
Console.WriteLine(sw.ElapsedTicks);
}
Run Code Online (Sandbox Code Playgroud) 我正在解决这个问题:
小女孩和最大总和
小女孩非常喜欢阵列查询的问题.
有一天,她遇到了一个众所周知的问题:你有一个n个元素的数组(数组的元素从1开始索引); 另外,有q个查询,每个查询由一对整数li,ri(1≤li≤ri≤n)定义.您需要为每个查询找到具有从li到ri(包括)的索引的数组元素的总和.
小女孩发现问题相当无聊.她决定在回复查询之前重新排序数组元素,使查询回复的总和最大化.您的任务是找到此最大总和的值.
输入第一行包含两个空格分隔的整数n(1≤n≤2·105)和q(1≤q≤2·105) - 数组中的元素数和相应的查询数.
下一行包含n个空格分隔的整数ai(1≤ai≤2·105) - 数组元素.
以下q行中的每一行包含两个空格分隔的整数li和ri(1≤li≤ri≤n) - 第i个查询.
输出在单行中打印单个整数 - 重新排序数组元素后查询答复的最大总和.
使用测试7(请参阅问题末尾的测试结果),输入是一个大小为200,000且包含200,000个查询(具有r和l值)的数组.
输入看起来像这样:
200000 200000
189622 189286 194361 184457 182376 183471 197548 184736 195806 ... 200,000 integers
188738 290041
33738 90041
122738 390041
... 200,000 line
Run Code Online (Sandbox Code Playgroud)
您可以下载示例输入文件,也可以创建自己的示例输入.数字本身并不重要.
我需要读取600,000条输入线,而不超过2秒的执行时间.问题是,它甚至没有在2秒内读取前200,000输入.
如何在2秒内加速我的代码读取所有600,000输入?
这是我的第一次尝试:
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int …Run Code Online (Sandbox Code Playgroud) execution-time ×10
java ×3
c# ×2
php ×2
c++ ×1
command-line ×1
dart-test ×1
django ×1
django-views ×1
flutter-test ×1
math ×1
optimization ×1
performance ×1
process ×1
python ×1
python-3.x ×1
theory ×1
time ×1
timing ×1
unit-testing ×1
wmi-query ×1