1、获取时间
struct timespec time_s, time_e; clock_gettime(CLOCK_MONOTONIC, &time_s);
计算时间,单位使用int_t,
(time_e.tv_sec - time_s.tv_sec) * 1000 + (time_e.tv_nsec - time_s.tv_nsec)/1000000;
2、for循环,只想带出其中20条插入和20条搜索的时间,和目前已写入多少条
for(int index, index < MAX_TEST_NO)
{
index++;//作为参数带入带出,只能index++
}
3、保证插入时间每条不同
#define START_T "2000-01-01 00:00:00" //第一条的记录时间为"2000-01-01 00:00:00"
uint32_t s_time = QDateTime::fromString(START_T, "yyyy-MM-dd hh:mm:ss").toTime_t();
QDateTime time_s = QDateTime::fromTime_t(s_time + index*900);//生成任意时间
time_s.toString("yyyy-MM-dd hh:mm:ss").toLocal8Bit().data();//字符串可以存入
4、保证每次搜索数据库任意10条
如果index未满足20条,则有一个值random_number =0;
超过20条,此index的前index-20条内,
random_number = rand() % (index - ONE_G_NO);//取余只到0 -(index-20)
srand((unsigned int) time(NULL));//初始化种子函数
int random_number ;
if(index < ONE_G_NO)
{
random_number = 0;
}
else
{
random_number = rand() % (index - ONE_G_NO);
}
uint32_t ut = QDateTime::fromString(START_T, "yyyy-MM-dd hh:mm:ss").toTime_t();
QDateTime time_string = QDateTime::fromTime_t(ut + random_number*900);
QString sql = QString::asprintf("select * from total_energyrecord_table where Start_t>= '%s' limit %d",time_string.toString("yyyy-MM-dd hh:mm:ss").toLocal8Bit().data(),ONE_G_NO);