08/02/29 17:06:38
>>484 多少は早いんじゃないかと思う。 20kで動かせないからわからないけど
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/time.h>
#include<math.h>
typedef unsigned char byte_t;
int srcsize;
int comp(const void *p1, const void *p2){ return memcmp(*(byte_t**)p1, *(byte_t**)p2, srcsize); }
int main(void){
int n;
byte_t *src, *blockarea, *tmp, **blocklst;
struct timeval stv={0}, etv={0};
srcsize=20000;
src = (byte_t *)calloc(sizeof(byte_t),srcsize);
blockarea = (byte_t *)calloc(sizeof(byte_t),(srcsize*srcsize));
blocklst = (byte_t **)calloc(sizeof(byte_t*),srcsize);
if(src == NULL || blockarea == NULL || blocklst == NULL){ return 1; }
for(n=0;n<srcsize;n++)src[n]=rand()&255;
gettimeofday(&stv, NULL);
memcpy(blockarea, src, srcsize);
blocklst[0] = blockarea;
for(n=1,tmp=blockarea+srcsize; n<srcsize; n++, tmp+=srcsize){
memcpy(tmp, src+n, srcsize-n);
memcpy(tmp+srcsize-n, src, n);
blocklst[n] = tmp;
}
qsort(blocklst, srcsize, sizeof(byte_t*), comp);
gettimeofday(&etv, NULL);
fprintf(stderr, "time %g sec\n", (etv.tv_sec-stv.tv_sec)+abs(etv.tv_usec-stv.tv_usec)/1000000.0);
return 0; }