ESP_LOGI
间隔 163813
微秒,平均下来一次 float 计算要 1 微秒,与芯片性能严重不符。请问是什么原因导致的呢?#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_log.h"
#define M2T(X) ((unsigned int)(X) / portTICK_PERIOD_MS) // ms to tick
#include "esp_random.h"
#include <sys/time.h>
static const char *TAG = "main";
#define dataLen 14400
void makeMatrixUint8(uint8_t *buf, int len)
{
for (int i = 0; i < len; i++)
{
esp_fill_random(&buf[i], sizeof(uint8_t));
}
}
void makeMatrixFloat(float *buf, int len)
{
for (int i = 0; i < len; i++)
{
esp_fill_random(&buf[i], sizeof(float));
}
}
static void testTask()
{
uint8_t *testData1 = (uint8_t *)malloc(sizeof(uint8_t) * dataLen);
float *testData2 = (float *)malloc(sizeof(float) * dataLen);
struct timeval tv_d0;
struct timeval tv_d1;
while (1)
{
makeMatrixUint8(testData1, dataLen);
makeMatrixFloat(testData2, dataLen);
gettimeofday(&tv_d0, NULL);
for (int t = 0; t < 10; t++)
{
for (int i = 0; i < dataLen; i++)
{
testData2[i] = testData1[i] * 0.3;
}
}
gettimeofday(&tv_d1, NULL);
ESP_LOGI(TAG, "%lu", 1000000 * (tv_d1.tv_sec - tv_d0.tv_sec) + (tv_d1.tv_usec - tv_d0.tv_usec));
vTaskDelay(1);
}
}
void app_main()
{
xTaskCreate(testTask, "servoTask", 1024 * 4, NULL, tskIDLE_PRIORITY, NULL);
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.