How do I keep a function in cache all the time in CPP?

at present, there is a function in a high-performance module in the project, which needs to be saved in cache all the time. A large number of other non-high-performance operations may be called during the execution of this function. The test result with rdtscp instruction shows that the performance of calling main_task for 10 times in a row is 10 times faster than that of executing some_task+main_task function, which should be the problem of cache miss.

remarks: linux system (centos)

the test sample code is as follows:

-sharpinclude <cmath>
-sharpinclude <ctime>
-sharpinclude <cstdlib>
-sharpinclude <iostream>
using namespace std;

static int datas[2 * 60 * 80 * 40];
static const int data_size = sizeof(datas) / sizeof(int);

void some_task()
{
        for (size_t i = 0; i < data_size * 60; PPi)
        {
            const int index = abs(rand()) % data_size;
            datas[index] = static_cast<int>(log(static_cast<double>(abs(rand()) + 1)));
        }
}

void main_task()
{
    /* ...do something... */
}

int main()
{
    for (size_t i = 0; i < 10; PPi)
    {
        some_task();
                /* start_time rdtscp */
        main_task();
                /* end_time rdtscp */
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bd6a86-30793.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bd6a86-30793.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?