(与查找列表中最低未使用的唯一ID以及在SQL表上获取未使用的唯一值相关)
假设我有一个包含id列和其他一些表的表(它们在这里没有任何区别):
+-----+-----+
| id |other|
+-----+-----+
Run Code Online (Sandbox Code Playgroud)
id具有数值增加值.我的目标是获得最低的未使用ID并创建该行.因此,当我第一次运行它将返回0并且该行的行将被创建.几次执行后,它将如下所示:
+-----+-----+
| id |other|
+-----+-----+
| 0 | ... |
| 1 | ... |
| 2 | ... |
| 3 | ... |
| 4 | ... |
+-----+-----+
Run Code Online (Sandbox Code Playgroud)
通常,这些行中的某些行可能会被删除.假设用的ID的行1和3移除.表格看起来不像这样:
+-----+-----+
| id |other|
+-----+-----+
| 0 | ... |
| 2 | ... |
| 4 | ... |
+-----+-----+
Run Code Online (Sandbox Code Playgroud)
如果我现在再次运行查询它想要返回id 1并且应该创建此行:
| id |other|
+-----+-----+
| 0 …Run Code Online (Sandbox Code Playgroud) 我想在我的项目中运行时获得实际的Mysql查询执行时间,因此在microtime()之前和之后运行PHP 并减去将无效.
当我们在命令行中运行查询时,结果显示如下的时序信息: -
xxx rows affected in YY sec
Run Code Online (Sandbox Code Playgroud)
如何使用PHP获取相同的时间信息.我搜索在PHP的MySQL函数在其他SO质疑这里,并在这里却没有得到类似的事情.有没有这样的PHP函数mysql_error(),mysql_affected_rows()它返回其他重要信息?如果不是为什么不存在?有什么理由吗?
有人说 -
我认为获得执行时间的最佳方法是使用一些程序执行函数,如exec()或system().
有没有人有一个可以返回实际执行时间的PHP代码?
我有一个注册使用的关闭功能register_shutdown_function()需要很长时间才能完成.PHP max_execution_time会导致PHP终止此函数还是会一直运行直到它完成或出错?
所以,只是为了好玩,出于好奇,我想看看在做奇偶校验,模数或按位比较时执行得更快.
所以,我掀起了以下内容,但我不确定它的表现是否正确,因为差异太小了.我在网上看到,按位应该比模数检查快一个数量级.
它是否有可能被优化掉?我刚刚开始修补程序集,否则我会尝试解析一下可执行文件.
编辑3:这是一个工作测试,非常感谢@phonetagger:
#include <stdio.h>
#include <time.h>
#include <stdint.h>
// to reset the global
static const int SEED = 0x2A;
// 5B iterations, each
static const int64_t LOOPS = 5000000000;
int64_t globalVar;
// gotta call something
int64_t doSomething( int64_t input )
{
return 1 + input;
}
int main(int argc, char *argv[])
{
globalVar = SEED;
// mod
clock_t startMod = clock();
for( int64_t i=0; i<LOOPS; ++i )
{
if( ( i % globalVar ) == 0 ) …Run Code Online (Sandbox Code Playgroud) 我做了一个Node.js应用程序,与另一个解决方案完全相同C#.这两个应用程序以递归方式从目录中获取所有javascript文件,并执行uglify-js命令以缩小文件.
我的项目有大约150个JavaScript文件要缩小,并且该C#方法需要大约22秒才能完成所有工作(使用线程).
在阅读了Node.js文档和书籍后,我决定这样做Node.js.我已经做到了,但我不能做报告总时间Node.js做的事情,因为它的异步方法...
(是的,我知道,我使用的线程C#也是异步的)
那么,什么是让Node.js应用程序总执行时间更好的方法呢?
我使用Node.js v0.10.13的是win32环境.
我想知道是否可以比在 Qt 应用程序中使用我的方法更快地加载样式表。
这是我的代码:
this->setStyleSheet("background-color : black;");
Run Code Online (Sandbox Code Playgroud)
执行这个简单的 css/qss 样式需要 270 毫秒。
使用此导入方法具有更大的 qss 样式
QFile file("style.qss");
if(!file.open(QFile::ReadOnly)){
qDebug() << "Style QSS file not found";
}
css = QString::fromLatin1(file.readAll());
file.close();
Run Code Online (Sandbox Code Playgroud)
这个命令
this->setStyleSheet(css);
Run Code Online (Sandbox Code Playgroud)
花了 330 毫秒,所以考虑到执行的 css 样式块的差异,这还不错。
所以看起来 setStyleShet 命令的 init 很长。我的问题是:有没有办法加快这个命令的速度(不使用 Qstring、其他导入方法……)或线程?
对我来说这很重要,因为我需要经常更新我的样式表,而且它花费的时间与我执行的所有逻辑一样多。
谢谢。祝你今天过得愉快 :)
我被困在我的一个功能需要一些时间来执行的地方.我使用对象模型和ArrayList(s)在对象中有一个对象层次结构.我只想知道调试代码的技术,以检查代码的哪个语句在执行时花费时间.
testing performance android performance-testing execution-time
我一直在网上寻找一段时间,试图找到这两个术语的定义和例子,但我似乎无法得到一个直接的答案,我只是变得更加困惑.
有人可以向我解释一下这个区别.一篇好的描述性文章会有所帮助.
operating-system resource-scheduling execution-time response-time completion
我发现我可以使用以下命令来测量Windows上的执行时间:
Measure-Command {start-process python .\script.py -Wait}
Run Code Online (Sandbox Code Playgroud)
而且效果很好。不幸的是,当我尝试运行带有一些(位置和可选)参数的脚本时,出现一条错误消息
Measure-Command {start-process python .\script.py file.txt 100 -Wait}
Run Code Online (Sandbox Code Playgroud)
我得到错误:
开始过程:找不到接受参数'file.txt'的位置参数。
没有Measure-Command,一切正常。
我究竟做错了什么?如何测量带有参数的脚本的执行时间?
我编写了以下代码来测量对任何数据进行排序的时间。我得到的结果很奇怪,例如在某些情况下为负时间,并且对于相同的数据集没有得到任何一致的结果(我知道这不会完全相同)。请让我知道哪里出了问题或如何正确测量时间。
#include<stdio.h>
#include<sys/time.h>
void bubble(int a[],int n)
{
int i,j,flag,temp;
for(i=0;i<n-1;i++)
{
flag=0;
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
flag=1;
a[j]=a[j]+a[j+1];
a[j+1]=a[j]-a[j+1];
a[j]=a[j]-a[j+1];
}
}
if(flag==0)
break;
}
}
int main()
{
int n,a[100000],i;
printf("Enter the size of array:");
scanf("%d",&n);
for(i=0;i<n;i++)
a[i]=rand()%100000; //average case
//a[i]=i; //best case
//a[i]=n-1-i; //worst case
/*
printf("The UNsorted array is:\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n\n");
*/
int st,et;
struct timezone tz;
struct timeval tv;
gettimeofday(&tv,NULL);
st=tv.tv_usec;
bubble(a,n);
gettimeofday(&tv,NULL);
et=tv.tv_usec;
printf("Sorting time: %d micro seconds\n",et-st);
/*
printf("\nThe sorted array …Run Code Online (Sandbox Code Playgroud) execution-time ×10
c ×2
php ×2
android ×1
clock ×1
completion ×1
function ×1
javascript ×1
mysql ×1
node.js ×1
performance ×1
powershell ×1
profiler ×1
python ×1
qt ×1
scalability ×1
shutdown ×1
sql ×1
stylesheet ×1
testing ×1
windows ×1