我一直有这个想法,减少迭代次数是的方式来使程序更加高效.由于我从未真正确认过,我开始测试这个.
我制作了以下C++程序来测量两个不同函数的时间:
完整的测试代码:
#include <iostream>
#include <chrono>
using namespace std;
int* list1; int* list2;
int* list3; int* list4;
int* list5; int* list6;
int* list7; int* list8;
int* list9; int* list10;
const int n = 1e7;
// **************************************
void myFunc1()
{
for (int i = 0; i < n; i++)
{
list1[i] = 2;
list2[i] = 4;
list3[i] = 8;
list4[i] = 16;
list5[i] = 32;
list6[i] = 64;
list7[i] = 128;
list8[i] = 256;
list9[i] = …
Run Code Online (Sandbox Code Playgroud) 简而言之: 与延迟减慢的类似循环相比,未延迟的while循环是否会消耗大量的处理能力?
在不那么短的时间内:
我经常遇到这个问题.我正在编写程序的核心部分(微控制器单元或计算机应用程序),它包含一个半无限的while循环,以保持活跃并查找事件.
我将采用这个例子:我有一个使用SDL窗口和控制台的小应用程序.在while循环中,我想监听此SDL窗口的事件,但我还想根据命令行输入通过全局变量来中断此循环.可能的解决方案(伪代码):
// Global
bool running = true;
// ...
while (running)
{
if (getEvent() == quit)
{
running = false;
}
}
shutdown();
Run Code Online (Sandbox Code Playgroud)
核心while循环将从已侦听的事件或外部事件中退出.但是,这个循环是连续运行的,甚至可能是每秒1000次.这有点过分杀人,我不需要那个响应时间.因此,我经常添加一个延迟声明:
while (running)
{
if (getEvent() == quit)
{
running = false;
}
delay(50); // Wait 50 milliseconds
}
Run Code Online (Sandbox Code Playgroud)
这将刷新率限制为每秒20次,这很充足.
所以.这两者之间有真正的区别吗?这很重要吗?在微控制器单元上是否会更加重要(处理能力非常有限(除了程序之外没有别的东西需要运行......))?
我的问题非常简单:表单数据应该如何(即名称键应该是什么样子)来使用patchEntities()
?
我已阅读 Cookbook > Database Access & ORM > Saving Data > Converting Multiple Records,但它没有明确提及如何使用它。
这种结构适用于newEntities()
:
$data = [
'0' => ['field1' => '...', /* ... */],
'1' => ['field1' => '...', /* ... */],
'2' => ['field1' => '...', /* ... */]
];
Run Code Online (Sandbox Code Playgroud)
使用如下形式:
<?= $this->Form->input('0.field1', /* ... */) ?>
<?= $this->Form->input('1.field1', /* ... */) ?>
...
Run Code Online (Sandbox Code Playgroud)
但是,相同的结构但 with'id.field1'
不会对patchEntities()
.
c++ ×2
loops ×2
performance ×2
benchmarking ×1
cakephp ×1
cakephp-3.0 ×1
forms ×1
orm ×1
sdl ×1