Mercurial > hg > Game > Cerium
view example/many_task/ppe/sort_test.cc @ 1852:7e9ebc1b08b6 draft
fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 21 Dec 2013 19:53:05 +0900 |
parents | b3644b73d2cf |
children |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include <stdlib.h> //#include "sort.h" #include "QuickSort.h" #include <sys/time.h> // sort.cc extern int data_length; extern DataPtr data; static int length = 1200; extern void qsort_test(Data*, int, int); static double getTime() { struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + (double)tv.tv_usec*1e-6; } void show( Data *data, int size ) { puts("-----------------------------------------------"); for(int i=0; i<=size; i++) printf("data[%02d].index = %d\n", i, data[i].index); puts("-----------------------------------------------"); return; } int init(int argc, char **argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "--length") == 0 || strcmp(argv[i], "-l") == 0) { length = atoi(argv[++i]); } } return 0; } Sort sorter; void check_data() { for(int i=0; i< sorter.data_length-1;i++) { if (sorter.data[i].index>sorter.data[i+1].index) { printf("Data are not sorted at %d. %d > %d \n",i, sorter.data[i].index,sorter.data[i+1].index); return; } } printf("Data are sorted\n"); } int main(int argc, char *argv[]) { if (init(argc, argv) < 0) { return -1; } sorter.data = new Data[length]; sorter.data_length = length; for (int i = 0; i < length; i++) { sorter.data[i].index = rand()%10000; sorter.data[i].ptr = i; } int begin = 0; int end = length; double st_time; double ed_time; //show(sorter.data, end-1); st_time = getTime(); qsort_test(sorter.data, begin, end); ed_time = getTime(); printf("Time: %0.6f\n",ed_time-st_time); //show(sorter.data, end-1); check_data(); return 0; }