long double stopwatch_stop (struct stopwatch_t* T) { if (T && T->is_running_) { get_time (&(T->t_stop_)); T->is_running_ = 0; } return stopwatch_elapsed (T); }
long double stopwatch_stop (struct stopwatch_t* T) { long double dt = 0; if (T) { if (IS_RUNNING (*T)) STAMP_STOP (*T); dt = stopwatch_elapsed (T); } return dt; }
long double stopwatch_stop (struct stopwatch_t* T) { long double dt = 0; if (T) { if (T->is_running_) { gettimeofday (&(T->t_stop_), 0); T->is_running_ = 0; } dt = stopwatch_elapsed (T); } return dt; }
/* Subversion delta editor callback */ static svn_error_t *de_apply_textdelta(void *file_baton, const char *base_checksum, apr_pool_t *pool, svn_txdelta_window_handler_t *handler, void **handler_baton) { apr_file_t *src_file = NULL, *dest_file = NULL; svn_stream_t *src_stream, *dest_stream; de_node_baton_t *node = (de_node_baton_t *)file_baton; dump_options_t *opts = node->de_baton->opts; #ifdef USE_TIMING stopwatch_t watch = stopwatch_create(); #endif char *filename; DEBUG_MSG("de_apply_textdelta(%s)\n", node->path); /* Create a new temporary file to write to */ node->filename = apr_psprintf(node->pool, "%s/XXXXXX", opts->temp_dir); apr_file_mktemp(&dest_file, node->filename, APR_CREATE | APR_READ | APR_WRITE | APR_EXCL, pool); dest_stream = svn_stream_from_aprfile2(dest_file, FALSE, pool); /* Update the local copy */ filename = rhash_get(delta_hash, node->path, APR_HASH_KEY_STRING); if (filename == NULL) { src_stream = svn_stream_empty(pool); } else { apr_file_open(&src_file, filename, APR_READ, 0600, pool); src_stream = svn_stream_from_aprfile2(src_file, FALSE, pool); } svn_txdelta_apply(src_stream, dest_stream, node->md5sum, node->path, pool, handler, handler_baton); node->old_filename = apr_pstrdup(node->pool, filename); rhash_set(delta_hash, node->path, APR_HASH_KEY_STRING, node->filename, RHASH_VAL_STRING); DEBUG_MSG("applied delta: %s -> %s\n", node->old_filename, node->filename); node->applied_delta = 1; node->dump_needed = 1; #ifdef USE_TIMING tm_de_apply_textdelta += stopwatch_elapsed(&watch); #endif return SVN_NO_ERROR; }
void main(void) { char* input_data = malloc(DATA_SIZE); FILE* input_file; input_file = fopen(INPUT_FILE, "r"); if(input_file == NULL){ fprintf(stderr, "Failed to open %s\n", INPUT_FILE); exit(1); } int i = 0; char buffer[BLOCK_SIZE]; while(fgets(buffer, BLOCK_SIZE, input_file)){ strcpy(input_data+i,buffer); i = i + BLOCK_SIZE - 1; } fclose(input_file); /*Replace the line field ascii with \0*/ input_data[strlen(input_data) - 1] = '\0'; struct stopwatch_t* sw = stopwatch_create(); /*--------------------------------------------------------------------------------------*/ stopwatch_init(); stopwatch_start(sw); printf("crcSlow() 0x%X ", crcSlow(input_data, strlen(input_data))); stopwatch_stop(sw); printf(" Time: %Lg\n", stopwatch_elapsed(sw)); /*--------------------------------------------------------------------------------------*/ stopwatch_start(sw); size_t input_data_len = strlen(input_data); int input_blocks = input_data_len / BLOCK_SIZE; int extra_blocks = 0; if(input_data_len % BLOCK_SIZE != 0) extra_blocks = 1; int total_blocks = input_blocks + extra_blocks; int *result = malloc(total_blocks * sizeof(int)); omp_set_num_threads(16); unsigned int ans = 0; char* block_data = malloc(input_blocks * (BLOCK_SIZE + 1)); char* block_addr; i = 0; #pragma omp parallel for default(none) shared(input_blocks, input_data, result, block_data) private (i, block_addr) for(i = 0; i < input_blocks; ++i){ block_addr = block_data + (BLOCK_SIZE + 1) * i; strncpy(block_addr, input_data + BLOCK_SIZE * i, BLOCK_SIZE); *(block_addr + BLOCK_SIZE) = '\0'; result[i] = CrcHash(block_addr, BLOCK_SIZE); } int rem = input_data_len % BLOCK_SIZE; char* last_block_data = malloc(rem + 1); if(extra_blocks == 1){ strncpy(last_block_data, input_data + BLOCK_SIZE * input_blocks, rem); *(last_block_data + rem) = '\0'; result[input_blocks] = CrcHash(last_block_data, rem); } i=0; for(i = 0; i < input_blocks; ++i){ ans = crc32_combine(ans, result[i], BLOCK_SIZE); } if(extra_blocks == 1) ans = crc32_combine(ans, result[i], rem); stopwatch_stop(sw); printf("Parallel() 0x%X Time: %Lg \n",ans, stopwatch_elapsed(sw)); /*--------------------------------------------------------------------------------------*/ crcInit(); stopwatch_start(sw); printf("crcFast() 0x%X ", crcFast(input_data, strlen(input_data))); stopwatch_stop(sw); printf(" Time: %Lg\n", stopwatch_elapsed(sw)); stopwatch_destroy(sw); /*--------------------------------------------------------------------------------------*/ stopwatch_start(sw); printf("crc_intel() 0x%X ", CrcHash((const void*)input_data, strlen(input_data))); stopwatch_stop(sw); printf(" Time: %Lg\n", stopwatch_elapsed(sw)); /*--------------------------------------------------------------------------------------*/ /*Cleanup*/ free(last_block_data); free(block_data); free(input_data); }