Skip to content

Commit

Permalink
wt-status: simplify performance measurement by using getnanotime()
Browse files Browse the repository at this point in the history
Calculating duration from a single uint64_t is simpler than from a struct
timeval. Change performance measurement for 'advice.statusuoption' from
gettimeofday() to getnanotime().

Also initialize t_begin to prevent uninitialized variable warning.

Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Karsten Blees authored and Junio C Hamano committed Jul 14, 2014
1 parent 578da03 commit 132d41e
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions wt-status.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,11 @@ static void wt_status_collect_untracked(struct wt_status *s)
{
int i;
struct dir_struct dir;
struct timeval t_begin;
uint64_t t_begin = getnanotime();

if (!s->show_untracked_files)
return;

if (advice_status_u_option)
gettimeofday(&t_begin, NULL);

memset(&dir, 0, sizeof(dir));
if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
dir.flags |=
Expand Down Expand Up @@ -612,13 +609,8 @@ static void wt_status_collect_untracked(struct wt_status *s)
free(dir.ignored);
clear_directory(&dir);

if (advice_status_u_option) {
struct timeval t_end;
gettimeofday(&t_end, NULL);
s->untracked_in_ms =
(uint64_t)t_end.tv_sec * 1000 + t_end.tv_usec / 1000 -
((uint64_t)t_begin.tv_sec * 1000 + t_begin.tv_usec / 1000);
}
if (advice_status_u_option)
s->untracked_in_ms = (getnanotime() - t_begin) / 1000000;
}

void wt_status_collect(struct wt_status *s)
Expand Down

0 comments on commit 132d41e

Please sign in to comment.