/*
* @Author: Mrnothing
* @Date: 2021-06-18 14:36:14
* @LastEditTime: 2021-06-18 15:28:33
* @LastEditors: Mrnothing
* @Description:
* @FilePath: \asyncc:\Users\Mrnothing\DOCUME~1\MobaXterm\slash\RemoteFiles\460430_2_99\main.cpp
* Copyright (c) 2020 KEDACOM.Co.Ltd All rights reserved
*/
#include <future>
#include <iostream>
// #include <stout/stringify.hpp>
// #include <stout/stringify.hpp>
#include "arm_neon.h"
#include <stdint.h>
#include <sys/time.h>
static unsigned int get_current_time(void)
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
int function1(unsigned char *pu8srcimg, unsigned char *pu8dstimg, int s32Height, int s32Width)
{
int n = 100000;
while(n--)
{
uint32_t T1 = get_current_time();
RGBHWC2RGBCHW_q(pu8srcimg, pu8dstimg, s32Height, s32Width);
uint32_t T2 = get_current_time();
// printf(" fun1 time:%dms \n",T2-T1);
}
return 0;
}
int function2(unsigned char *pu8srcimg, unsigned char *pu8dstimg, int s32Height, int s32Width)
{
int n = 100000;
while(n--)
{
uint32_t T1 = get_current_time();
RGBHWC2RGBCHW(pu8srcimg, pu8dstimg, s32Height, s32Width);
uint32_t T2 = get_current_time();
printf(" fun2 time:%dms \n",T2-T1);
}
return 0;
}
int main()
{
uint32_t u32W = 4096;
uint32_t u32H = 2176;
uint8_t *pu8src = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint8_t *pu8dst = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint8_t *pu8src1 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint8_t *pu8dst1 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint8_t *pu8src2 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint8_t *pu8dst2 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint8_t *pu8src3 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint8_t *pu8dst3 = (uint8_t *)calloc(1, sizeof(uint8_t)*u32W*u32H*3);
uint32_t T1 = get_current_time();
std::future<int> Fun0 = std::async(function1, pu8src, pu8dst, u32H, u32W);
std::future<int> Fun1 = std::async(function2, pu8src1, pu8dst1, u32H, u32W);
std::future<int> Fun2 = std::async(function1, pu8src2, pu8dst2, u32H, u32W);
std::future<int> Fun3 = std::async(function2, pu8src3, pu8dst3, u32H, u32W); // 增加线程,占用的核心数增加
// printf("please wait");
// std::chrono::milliseconds span(1000);
// while (Fun0.wait_for(span) != std::future_status::ready)
// printf("--->");
// printf("\n");
int ret = Fun0.get();
ret = Fun1.get();
ret = Fun2.get();
ret = Fun3.get();
uint32_t T3 = get_current_time();
printf(" fun(%d) time:%dms \n",ret, T3-T1);
free(pu8src);
free(pu8dst);
free(pu8src1);
free(pu8dst1);
free(pu8src2);
free(pu8dst2);
free(pu8src3);
free(pu8dst3);
return 0;
}
参考:https://blog.youkuaiyun.com/u012372584/article/details/97108417