Last active
May 9, 2019 15:18
-
-
Save iconjack/1e889d96c47506f08e1756a4a26407f5 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include <string.h> | |
#include <time.h> | |
typedef uint8_t byte; | |
typedef uint32_t quart; | |
typedef uint64_t pottle; | |
void poppop32(void *P, int n) | |
{ | |
quart *p = (quart *) P; | |
*p++ = 0x02010100; | |
n -= 2; | |
int size = 1; | |
while (n) | |
{ | |
quart *q = (quart *) P; | |
for (int i = 0; i < size; i++) | |
*p++ = *q++ + 0x01010101; | |
size += size; | |
n -= 1; | |
} | |
} | |
void poppop64(void *P, int n) | |
{ | |
pottle *p = (pottle *) P; | |
*p++ = 0x0302020102010100; | |
n -= 3; | |
int size = 1; | |
while (n) | |
{ | |
pottle *q = (pottle *) P; | |
for (int i = 0; i < size; i++) | |
*p++ = *q++ + 0x0101010101010101; | |
size += size; | |
n -= 1; | |
} | |
} | |
int main() | |
{ | |
int N = 26; | |
void *P = malloc(1 << N); | |
clock_t start, end; | |
double millis; | |
memset(P, 0, 1 << N); | |
start = clock(); | |
poppop32(P, N); | |
end = clock(); | |
millis = ((double)(end - start)) / CLOCKS_PER_SEC * 1000; | |
printf("poppop32: %.1f ms\n", millis); | |
memset(P, 0, 1 << N); | |
start = clock(); | |
poppop64(P, N); | |
end = clock(); | |
millis = ((double)(end - start)) / CLOCKS_PER_SEC * 1000; | |
printf("poppop64: %.1f ms\n", millis); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment