Advertisement
Guest User

task2.c

a guest
Nov 14th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.36 KB | None | 0 0
  1. //==== NOTE ==================================================================
  2. // You do not need to change anything in this file, but feel free to read it
  3. // if it is of interest.
  4. //
  5. // You only need to update bstdb.c
  6. //============================================================================
  7.  
  8. #include "db/database.h"
  9. #include "db/profiler.h"
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13.  
  14. //=== FUNCTION ================================================================
  15. //         Name: profile
  16. //  Description: Bind to a database using the function pointer passed as an
  17. //               argument and run our simple profiling tests to assess its
  18. //               performance.
  19. //=============================================================================
  20. void
  21. profile ( char *dbname, void (*bind)(struct database *db) ) {
  22.     struct database db;
  23.     struct profile p;
  24.  
  25.     // Bind to the appropriate database
  26.     bind(&db);
  27.  
  28.     printf("\nProfiling %s\n", dbname);
  29.     printf("-------------------------------------------\n\n");
  30.  
  31.     // Attempt to initialize the database
  32.     if (!db.init()) {
  33.         printf("%s failed to initialize\n", dbname);
  34.         return;
  35.     }
  36.  
  37.     // point the profiler at the database
  38.     p.db = &db;
  39.  
  40.     // run the profiler
  41.     profiler_run(&p);
  42.  
  43.     // print results of profiling
  44.     printf("Total Inserts                : %12d\n", p.total_insert);
  45.     printf("Num Insert Errors            : %12d\n", p.insert_errors);
  46.     printf("Avg Insert Time              : %10.6f s\n", p.avg_insert_time);
  47.     printf("Var Insert Time              : %10.6f s\n", p.var_insert_time);
  48.     printf("Total Insert Time            : %10.6f s\n", p.total_insert_time);
  49.     printf("\n");
  50.     printf("Total Title Searches         : %12d\n", p.total_search_title);
  51.     printf("Num Title Search Errors      : %12d\n", p.search_title_errors);
  52.     printf("Avg Title Search Time        : %10.6f s\n",
  53.         p.avg_search_time_title);
  54.     printf("Var Title Search Time        : %10.6f s\n",
  55.         p.var_search_time_title);
  56.     printf("Total Title Search Time      : %10.6f s\n",
  57.         p.total_search_time_title);
  58.     printf("\n");
  59.     printf("Total Word Count Searches    : %12d\n",
  60.         p.total_search_word_count);
  61.     printf("Num Word Count Search Errors : %12d\n",
  62.         p.search_word_count_errors);
  63.     printf("Avg Word Count Search Time   : %10.6f s\n",
  64.         p.avg_search_time_word_count);
  65.     printf("Var Word Count Search Time   : %10.6f s\n",
  66.         p.var_search_time_word_count);
  67.     printf("Total Word Count Search Time : %10.6f s\n",
  68.         p.total_search_time_word_count);
  69.     printf("\n");
  70.  
  71.     // show off
  72.     db.stat();
  73.  
  74.     // close the database
  75.     db.quit();
  76. }
  77.  
  78. //=== FUNCTION ================================================================
  79. //         Name: main
  80. //  Description: Program entry point
  81. //=============================================================================
  82. int
  83. main ( int argc, char *argv[] ) {
  84.     if (!profiler_init()) {
  85.         printf("Profiler failed to initialize\n");
  86.         return EXIT_FAILURE;
  87.     }
  88.  
  89.     // you can comment out this line to ignore profiling the linked list
  90.     profile( "listdb", database_bind_listdb );
  91.  
  92.     profile( "bstdb", database_bind_bstdb );
  93.  
  94.     profiler_quit();
  95.  
  96.     puts("Press Enter to quit...");
  97.     fgetc(stdin);
  98.  
  99.     return EXIT_SUCCESS;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement