这是一段看似非常特殊的C++代码.出于某种奇怪的原因,奇迹般地对数据进行排序使得代码几乎快了六倍.
#include <algorithm>
#include <ctime>
#include <iostream>
int main()
{
// Generate data
const unsigned arraySize = 32768;
int data[arraySize];
for (unsigned c = 0; c < arraySize; ++c)
data[c] = std::rand() % 256;
// !!! With this, the next loop runs faster.
std::sort(data, data + arraySize);
// Test
clock_t start = clock();
long long sum = 0;
for (unsigned i = 0; i < 100000; ++i)
{
// Primary loop
for (unsigned c = 0; c < arraySize; ++c) …Run Code Online (Sandbox Code Playgroud) Java API中有许多内在函数的方法,但在查看源代码时仍然有与它们相关的代码.
例如,Integer.bitCount()是一个内在函数,但如果打开Integer类文件,则可以看到它的代码.
如果编译器/ jvm不一定使用此代码,那么该代码可以用于什么目的?
java ×3
benchmarking ×1
c++ ×1
intrinsics ×1
jvm ×1
jvm-hotspot ×1
optimization ×1
performance ×1