-
-
Save egonelbre/f4fd5ae3a99e2b7317f0ac63c17ed859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program Benchmark; | |
{$APPTYPE CONSOLE} | |
uses | |
Windows, | |
SysUtils, | |
FastMove; | |
const | |
ITERATIONS = 1000000; | |
var | |
Buffer: array[0..128 shl 20] of Byte; // should be enough to not overwrite in memory... maybe? :P | |
function BenchFastCode(AForward: Boolean; N: Integer): Extended; | |
var | |
qs, qe, qf: Int64; | |
i: Integer; | |
begin | |
QueryPerformanceCounter(qs); | |
if AForward then | |
begin | |
for i := 1 to ITERATIONS do | |
FastMove.Move(Buffer[i], Buffer[i + N], N); | |
end | |
else | |
begin | |
for i := 1 to ITERATIONS do | |
FastMove.Move(Buffer[i + N], Buffer[i], N); | |
end; | |
QueryPerformanceCounter(qe); | |
QueryPerformanceFrequency(qf); | |
Result := (qe - qs) * 1e9 / (qf * ITERATIONS); | |
end; | |
const | |
at: array[0..25] of Integer = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 16, 17, 29, 31, 32, 45, 54, 62, 79, 93, 121, 128, 4096, 4096*4, 4096*16); | |
var | |
i: Integer; | |
begin | |
for i := Low(at) to High(at) do | |
Writeln(at[i]: 10, BenchFastCode(True, at[i]): 10: 3, BenchFastCode(False, at[i]): 10: 3); | |
readln; | |
end. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
#include "stdint.h" | |
#include "apex_memmove.h" | |
#include "apex_memmove.c" | |
#define ITERATIONS 1000000 | |
uint8_t Buffer[128<<20]; | |
double runbench(bool forward, size_t n){ | |
LARGE_INTEGER qs, qe, qf; | |
QueryPerformanceCounter(&qs); | |
if(forward){ | |
for(size_t i = 0; i < ITERATIONS; i++){ | |
apex::memmove(&Buffer[i+n], &Buffer[i], n); | |
} | |
} else { | |
for(size_t i = 0; i < ITERATIONS; i++){ | |
apex::memmove(&Buffer[i], &Buffer[i+n], n); | |
} | |
} | |
QueryPerformanceCounter(&qe); | |
QueryPerformanceFrequency(&qf); | |
return (qe.QuadPart - qs.QuadPart) * 1e9 / (qf.QuadPart * ITERATIONS); | |
} | |
double runbenchstd(bool forward, size_t n){ | |
LARGE_INTEGER qs, qe, qf; | |
QueryPerformanceCounter(&qs); | |
if(forward){ | |
for(size_t i = 0; i < ITERATIONS; i++){ | |
memmove(&Buffer[i+n], &Buffer[i], n); | |
} | |
} else { | |
for(size_t i = 0; i < ITERATIONS; i++){ | |
memmove(&Buffer[i], &Buffer[i+n], n); | |
} | |
} | |
QueryPerformanceCounter(&qe); | |
QueryPerformanceFrequency(&qf); | |
return (qe.QuadPart - qs.QuadPart) * 1e9 / (qf.QuadPart * ITERATIONS); | |
} | |
int main() { | |
int at[26] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 16, 17, 29, 31, 32, 45, 54, 62, 79, 93, 121, 128, 4096, 4096*4, 4096*16}; | |
for(size_t i = 0; i < 26; i++){ | |
printf("%10d %10.3f %10.3f\n", at[i], runbench(true, at[i]), runbench(false, at[i])); | |
} | |
for(size_t i = 0; i < 26; i++){ | |
printf("%10d %10.3f %10.3f\n", at[i], runbenchstd(true, at[i]), runbenchstd(false, at[i])); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment