static void perftest_nway_mergesort(const struct gheap_ctx *const ctx, T *const a, const size_t n, const size_t m) { const size_t small_range_size = ((1 << 20) - 1) / 3; const size_t subranges_count = 15; printf("perftest_nway_mergesort(n=%zu, m=%zu, small_range_size=%zu, " "subranges_count=%zu)", n, m, small_range_size, subranges_count); double total_time = 0; struct gheap_ctx small_range_sorter_ctx = *ctx; small_range_sorter_ctx.fanout = 4; for (size_t i = 0; i < m / n; ++i) { init_array(a, n); const double start = get_time(); T *const items_tmp_buf = malloc(sizeof(items_tmp_buf[0]) * n); galgorithm_nway_mergesort(ctx, a, n, &small_range_sorter, &small_range_sorter_ctx, small_range_size, subranges_count, items_tmp_buf); free(items_tmp_buf); const double end = get_time(); total_time += end - start; } print_performance(total_time, m); }
int main () { int x = 1; while (x == 1) { int selection; printf("\nPerformance Assessment: \n"); printf("-----------------------\n"); printf("1) Enter parameters\n"); printf("2) Print table of parameters\n"); printf("3) Print table of performance\n"); printf("4) Quit\n\n"); printf("Enter Selection: "); scanf("%d", &selection); if (selection == 1) enter_params(); else if (selection == 2) print_params(); else if (selection == 3) print_performance(); else if (selection == 4) { deallocate_memory(); x = 2; } } return 0; }
static size_t critbit_sort(uintptr_t *const a, const size_t n) { struct node_storage *const s = create_node_storage(n); const struct critbit_node_allocator node_allocator = { .alloc_node = &alloc_critbit_node, .free_node = &free_critbit_node, .ctx = s, }; struct critbit *const cb = critbit_create(&node_allocator); size_t m = n; for (size_t i = 0; i < n; ++i) { if (!critbit_add(cb, a[i])) { --m; } } struct sort_data data = { .a = a, .offset = 0, }; const struct critbit_visitor sort_visitor = { .callback = &sort_callback, .ctx = &data, }; critbit_foreach(cb, &sort_visitor); assert(data.offset == m); critbit_delete(cb); delete_node_storage(s); return data.offset; } static void test_sort(const size_t n, const size_t m) { printf("test_sort(n=%zu, m=%zu)", n, m); uintptr_t *const a = malloc(sizeof(a[0]) * n); double total_time = 0; srand(0); for (size_t i = 0; i < m / n; ++i) { init_array(a, n); double start = get_time(); critbit_sort(a, n); double end = get_time(); total_time += end - start; } print_performance(total_time, m); free(a); }
static void print_stats(void) { print_performance(); if (g_latency_tracking_enable) { if (g_rw_percentage != 0) { print_latency_statistics("Read", SPDK_NVME_INTEL_LOG_READ_CMD_LATENCY); } if (g_rw_percentage != 100) { print_latency_statistics("Write", SPDK_NVME_INTEL_LOG_WRITE_CMD_LATENCY); } } }
static void perftest_heapsort(const struct gheap_ctx *const ctx, T *const a, const size_t n, const size_t m) { printf("perftest_heapsort(n=%zu, m=%zu)", n, m); double total_time = 0; for (size_t i = 0; i < m / n; ++i) { init_array(a, n); const double start = get_time(); galgorithm_heapsort(ctx, a, n); const double end = get_time(); total_time += end - start; } print_performance(total_time, m); }
static void perftest_priority_queue(const struct gheap_ctx *const ctx, T *const a, const size_t n, const size_t m) { printf("perftest_priority_queue(n=%zu, m=%zu)", n, m); init_array(a, n); struct gpriority_queue *const q = gpriority_queue_create_from_array( ctx, &delete_item, a, n); double start = get_time(); for (size_t i = 0; i < m; ++i) { gpriority_queue_pop(q); const T tmp = rand(); gpriority_queue_push(q, &tmp); } double end = get_time(); gpriority_queue_delete(q); print_performance(end - start, m); }
static void Display( void ) { float ambient[] = {0.1, 0.1, 0.1, 1.0}; float diffuse[] = {1.0, 1.0, 1.0, 1.0}; float position[] = {0.0, 1.0, 0.0, 0.0}; float mat_shininess[] = {90.0}; float mat_specular[] = {0.8, 0.8, 0.8, 1.0}; float mat_diffuse[] = {0.46, 0.66, 0.795, 1.0}; float mat_ambient[] = {0.0, 0.1, 0.2, 1.0}; float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0}; float lmodel_localviewer[] = {0.0}; int i; #if 0 /* stupid WireGL */ glViewport (0, 0, 450*3, 170*3); #endif glFrontFace(GL_CCW); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glClearColor(0.0, 0.5, 0.9, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40.0, 2.0, 10000.0, 400000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (i = 0; i < NumSharks; i++) { glPushMatrix(); FishTransform(&sharks[i]); DrawShark(&sharks[i]); glPopMatrix(); } glPushMatrix(); FishTransform(&dolph); DrawDolphin(&dolph); glPopMatrix(); glPushMatrix(); FishTransform(&momWhale); DrawWhale(&momWhale); glPopMatrix(); glPushMatrix(); FishTransform(&babyWhale); glScalef(0.45, 0.45, 0.3); DrawWhale(&babyWhale); glPopMatrix(); if ( screenshot ) save_frame( ); screenshot = 0; glutSwapBuffers( ); print_performance( ); }
int main(int argc, char* argv[]) { printf("[i] Start...\n"); char file_name[] = "test.bmp"; char* filename=file_name; if(argc >= 2) { filename = argv[1]; } printf("[i] file: %s\n", filename); image* img = image_create(320, 240, 3, CV_DEPTH_8U); if(!img) { printf("[!] Error: image_create()\n"); return -1; } image_delete(&img); // test image loading image* img2 = image_load(filename); printf("[i] image size: %dx%dx%d (%d)\n", img2->width, img2->height, img2->n_channels, img2->size); image_save(img2, "test2_load_save.bmp"); printf("[i] == Tests == \n"); #if 1 // copy printf("[i] image_copy \n"); img = image_create(img2->width, img2->height, img2->n_channels, CV_DEPTH_8U); image_copy(img2, img); image_save(img, "test2_copy.bmp"); // test convert image to grayscale printf("[i] image_convert_color \n"); image* img_gray = image_create(img2->width, img2->height, 1, CV_DEPTH_8U); gettimeofday(&t0, NULL); image_convert_color(img2, img_gray, CV_RGB2GRAY); gettimeofday(&t1, NULL); image_save(img_gray, "test3_gray.bmp"); // test borders detection printf("[i] image_thin_borders \n"); image* img_borders = NULL; gettimeofday(&t2, NULL); image_thin_borders(img_gray, &img_borders); gettimeofday(&t3, NULL); image_save(img_borders, "test4_thin_borders.bmp"); // min-max-loc printf("[i] image_min_max_loc \n"); double _min, _max; gettimeofday(&t4, NULL); image_min_max_loc(img_gray, &_min, &_max, NULL, NULL); gettimeofday(&t5, NULL); printf("[i] min=%0.2f max=%0.2f\n", _min, _max); // threshold printf("[i] image_threshold \n"); image* img_thr = image_create(img2->width, img2->height, 1, CV_DEPTH_8U); gettimeofday(&t6, NULL); image_threshold(img_gray, img_thr, 60); gettimeofday(&t7, NULL); image_save(img_thr, "test5_threshold.bmp"); #endif #if 1 // rotate180 printf("[i] image_rotate180 \n"); image_rotate180(img2); image_save(img2, "test6_rotate180.bmp"); image_rotate180(img2); // reflect vertical printf("[i] image_reflect_vertical \n"); image_reflect_vertical(img2); image_save(img2, "test7_reflect_vertical.bmp"); image_reflect_vertical(img2); #endif // rotate180 int colors_count; cv_point center; #if 1 // simple resize printf("[i] image_resize \n"); image *img_small = image_create(160, 120, 3, CV_DEPTH_8U); gettimeofday(&t8, NULL); image_resize(img2, img_small); gettimeofday(&t9, NULL); image_save(img_small, "test8_resize.bmp"); // image* img_small_gray = image_create(80, 60, 1, CV_DEPTH_8U); // image_convert_color(img_small, img_small_gray, CV_RGB2GRAY); // image* img_small_borders = NULL; // image_thin_borders(img_small_gray, &img_small_borders); // image_save(img_small_borders, "test_resize_thin_borders.bmp"); #if 1 // k-meanes colorer printf("[i] image_kmeans_colorer \n"); image* img_kmeanes = image_create(160, 120, 3, CV_DEPTH_8U); image* img_kmeanes_idx = image_create(160, 120, 1, CV_DEPTH_8U); #define CLUSTER_COUNT 10 int cluster_count = CLUSTER_COUNT; cv_color_cluster clusters[CLUSTER_COUNT]; gettimeofday(&t10, NULL); colors_count = image_kmeans_colorer(img_small, img_kmeanes, img_kmeanes_idx, clusters, cluster_count); gettimeofday(&t11, NULL); printf("[i] colors count: %d\n", colors_count); image_save(img_kmeanes, "test_kmeanscolorer.bmp"); #if 0 print_color_clusters(clusters, CLUSTER_COUNT); printf("[i] === colors clusters after sort:\n"); sort_color_clusters_by_count(clusters, CLUSTER_COUNT); print_color_clusters(clusters, CLUSTER_COUNT); #endif image_delete(&img_kmeanes); image_delete(&img_kmeanes_idx); #endif // k-meanes colorer image_delete(&img_small); // image_delete(&img_small_gray); // image_delete(&img_small_borders); #endif // simple resize #if 1 // HSV printf("[i] image_hsv2rgb \n"); image* img_hsv = image_create(img2->width, img2->height, 3, CV_DEPTH_8U); image* img_bgr = image_create(img2->width, img2->height, 3, CV_DEPTH_8U); gettimeofday(&t12, NULL); image_rgb2hsv(img2, img_hsv); gettimeofday(&t13, NULL); image_hsv2rgb(img_hsv, img_bgr); image_save(img_hsv, "test9_rgb2hsv.bmp"); image_save(img_bgr, "test9_hsv2rgb.bmp"); image_delete(&img_hsv); image_delete(&img_bgr); #endif // HSV #if 1 // hsv colorer printf("[i] image_hsv_colorer \n"); image* img_hsv_col = image_create(img2->width, img2->height, 3, CV_DEPTH_8U); image* img_hsv_idx = image_create(img2->width, img2->height, 1, CV_DEPTH_8U); #define COLORS_COUNT 10 cv_color_cluster clusters2[COLORS_COUNT]; gettimeofday(&t14, NULL); colors_count = image_hsv_colorer(img2, img_hsv_col, img_hsv_idx, clusters2, COLORS_COUNT); gettimeofday(&t15, NULL); printf("[i] colors count: %d\n", colors_count); image_save(img_hsv_col, "test_hsvcolorer.bmp"); #if 1 print_color_clusters(clusters2, COLORS_COUNT); printf("[i] === colors clusters after sort:\n"); sort_color_clusters_by_count(clusters2, COLORS_COUNT); print_color_clusters(clusters2, COLORS_COUNT); center = get_color_center(clusters2[0].id, img_hsv_idx); printf("[i] first color center: %03d %03d\n", center.x, center.y); center = get_color_center(clusters2[1].id, img_hsv_idx); printf("[i] second color center: %03d %03d\n", center.x, center.y); center = get_color_center(clusters2[2].id, img_hsv_idx); printf("[i] third color center: %03d %03d\n", center.x, center.y); #endif // print_color_clusters image_delete(&img_hsv_col); image_delete(&img_hsv_idx); #endif // hsv colorer printf("[i] == Performance == \n"); print_performance("image_convert_color", t1, t0); print_performance("image_thin_borders", t3, t2); print_performance("image_min_max_loc", t5, t4); print_performance("image_threshold", t7, t6); print_performance("image_resize", t9, t8); print_performance("image_kmeans_colorer", t11, t10); print_performance("image_rgb2hsv", t13, t12); print_performance("image_hsv_colorer", t15, t14); image_delete(&img); image_delete(&img2); #if 1 image_delete(&img_gray); image_delete(&img_borders); image_delete(&img_thr); #endif printf("[i] End.\n"); return 0; }