Der Code:
Code: Alles auswählen
#include <windows.h>
#include <iostream>
#include <stdio.h>
LARGE_INTEGER start, end, frequency;
int AbsoluteXin( int i )
{
if( *reinterpret_cast< unsigned int * >( &i ) & 0x80 ) return ~i+1;
return i;
}
int AbsoluteCloidnerux(int a)
{
return ((a < 0)?(~(a-1)):(a));
}
const int HALFRANGE = 0x80000000;
int AbsoluteFatLobyte(int x)
{
int submask = x >> 31;
x += HALFRANGE;
x += HALFRANGE - ((x & submask) << 1);
return x;
}
int AbsoluteFatLobyte2(int x)
{
int submask = x >> 31;
x -= ((x & submask) << 1);
return x;
}
void TestFunction(int (*TestFunction)(int))
{
for(int i = -100000; i < 100000; i++)
{
if(TestFunction(i) != ((i < 0)?(i*-1):(i)))
{
std::cout << TestFunction(i) << " " << i << " failed!" << std::endl;
return;
}
}
QueryPerformanceCounter(&start);
for(int i = -10000000; i < 10000000; i++)
{
TestFunction(i);
}
QueryPerformanceCounter(&end);
double elapsed = (double)(end.QuadPart - start.QuadPart) / (double)(frequency.QuadPart);
std::cout << "Time: " << elapsed << std::endl;
}
int main()
{
if(!QueryPerformanceFrequency(&frequency))
{
std::cout << "Performance counter not supported!" << std::endl;
return 0;
}
for(int i = 0; i < 10; i++)
{
std::cout << "Durchgang: " << i << std::endl;
std::cout << "cloidnerux: ";
TestFunction(AbsoluteCloidnerux);
std::cout << "Xin: ";
TestFunction(AbsoluteXin);
std::cout << "Fat-Lobyte: ";
TestFunction(AbsoluteFatLobyte);
std::cout << "Fat-Lobyte2: ";
TestFunction(AbsoluteFatLobyte);
}
return 0;
}
Code: Alles auswählen
Durchgang: 0
cloidnerux: Time: 1.02007
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.974177
Fat-Lobyte2: Time: 0.981317
Durchgang: 1
cloidnerux: Time: 0.953523
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.990207
Fat-Lobyte2: Time: 0.972756
Durchgang: 2
cloidnerux: Time: 0.952685
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.997275
Fat-Lobyte2: Time: 1.03233
Durchgang: 3
cloidnerux: Time: 0.983867
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 1.07335
Fat-Lobyte2: Time: 1.08516
Durchgang: 4
cloidnerux: Time: 0.938563
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 1.00118
Fat-Lobyte2: Time: 0.987632
Durchgang: 5
cloidnerux: Time: 0.946707
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.979446
Fat-Lobyte2: Time: 1.10497
Durchgang: 6
cloidnerux: Time: 1.01846
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 1.30061
Fat-Lobyte2: Time: 1.14477
Durchgang: 7
cloidnerux: Time: 0.961695
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 1.0205
Fat-Lobyte2: Time: 1.1046
Durchgang: 8
cloidnerux: Time: 0.941668
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 1.04531
Fat-Lobyte2: Time: 1.03076
Durchgang: 9
cloidnerux: Time: 0.936019
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.973315
Fat-Lobyte2: Time: 1.0083
Code: Alles auswählen
Durchgang: 0
cloidnerux: Time: 0.118843
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.116535
Fat-Lobyte2: Time: 0.117512
Durchgang: 1
cloidnerux: Time: 0.116734
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.117401
Fat-Lobyte2: Time: 0.119287
Durchgang: 2
cloidnerux: Time: 0.11475
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.115192
Fat-Lobyte2: Time: 0.115893
Durchgang: 3
cloidnerux: Time: 0.118736
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.119174
Fat-Lobyte2: Time: 0.118722
Durchgang: 4
cloidnerux: Time: 0.118791
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.123701
Fat-Lobyte2: Time: 0.123066
Durchgang: 5
cloidnerux: Time: 0.11262
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.112666
Fat-Lobyte2: Time: 0.1144
Durchgang: 6
cloidnerux: Time: 0.117093
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.111267
Fat-Lobyte2: Time: 0.11453
Durchgang: 7
cloidnerux: Time: 0.112701
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.112284
Fat-Lobyte2: Time: 0.112488
Durchgang: 8
cloidnerux: Time: 0.112713
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.115529
Fat-Lobyte2: Time: 0.114998
Durchgang: 9
cloidnerux: Time: 0.111399
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.111935
Fat-Lobyte2: Time: 0.113689
Code: Alles auswählen
Durchgang: 0
cloidnerux: Time: 0.128479
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.112748
Fat-Lobyte2: Time: 0.117027
Durchgang: 1
cloidnerux: Time: 0.115995
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.11165
Fat-Lobyte2: Time: 0.111743
Durchgang: 2
cloidnerux: Time: 0.113584
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.114818
Fat-Lobyte2: Time: 0.114798
Durchgang: 3
cloidnerux: Time: 0.110545
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.108895
Fat-Lobyte2: Time: 0.108947
Durchgang: 4
cloidnerux: Time: 0.10894
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.114672
Fat-Lobyte2: Time: 0.109757
Durchgang: 5
cloidnerux: Time: 0.109177
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.109285
Fat-Lobyte2: Time: 0.109069
Durchgang: 6
cloidnerux: Time: 0.109543
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.117185
Fat-Lobyte2: Time: 0.110174
Durchgang: 7
cloidnerux: Time: 0.109838
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.109862
Fat-Lobyte2: Time: 0.117252
Durchgang: 8
cloidnerux: Time: 0.115763
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.116145
Fat-Lobyte2: Time: 0.135786
Durchgang: 9
cloidnerux: Time: 0.125808
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.125284
Fat-Lobyte2: Time: 0.115544
Code: Alles auswählen
Durchgang: 0
cloidnerux: Time: 0.0849635
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0956691
Fat-Lobyte2: Time: 0.0926058
Durchgang: 1
cloidnerux: Time: 0.0778466
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0893933
Fat-Lobyte2: Time: 0.087585
Durchgang: 2
cloidnerux: Time: 0.0768679
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0877169
Fat-Lobyte2: Time: 0.0892249
Durchgang: 3
cloidnerux: Time: 0.0767437
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0905347
Fat-Lobyte2: Time: 0.0893481
Durchgang: 4
cloidnerux: Time: 0.0764694
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0880393
Fat-Lobyte2: Time: 0.0879141
Durchgang: 5
cloidnerux: Time: 0.0776811
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0883155
Fat-Lobyte2: Time: 0.0871818
Durchgang: 6
cloidnerux: Time: 0.0767918
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0874031
Fat-Lobyte2: Time: 0.0886975
Durchgang: 7
cloidnerux: Time: 0.0786858
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.087149
Fat-Lobyte2: Time: 0.0885176
Durchgang: 8
cloidnerux: Time: 0.0774453
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0883684
Fat-Lobyte2: Time: 0.0882981
Durchgang: 9
cloidnerux: Time: 0.0777648
Xin: -100000 -100000 failed!
Fat-Lobyte: Time: 0.0880373
Fat-Lobyte2: Time: 0.0881971