gettimeofday 함수 질문입니다

neon20의 이미지

함수를 호출하고 tv_usec 값을 출력해보면
대개 -1.XXXXXX 형태의 숫자값으로 나옵니다.
이 숫자값이 뜻하는게 정확히 무엇인가요?
그리고 이값은 변경이 불가능한가요?
예를 들어서
b = tv_usec;
로 b에 값을 배정 받았을 때
b = b*1000;
이라고 해도 b의 값은 변경이 되지 않습니다.
도와주세요..ㅠㅠ

cdpark의 이미지

neon20 wrote:
함수를 호출하고 tv_usec 값을 출력해보면
대개 -1.XXXXXX 형태의 숫자값으로 나옵니다.
이 숫자값이 뜻하는게 정확히 무엇인가요?

어떻게 찍으셨기에? tv_usec 값은 Linux에서는 long int형입니다. 혹시 long int를 %f로 찍으신 건 아니시죠?

익명 사용자의 이미지

0<= tv_usec < 1,000,000 인 정수입니다.
즉, 0~999,999인 정수값을 유효숫자로 합니다.

1) 0은 0 micro second
2) 999,999 = 999,999 micro second = 0.999999초(second)
3) 500,000 = 0.5초
...

익명 사용자의 이미지

초로 환산하려면 백만(1,000,000)으로 나눠야 겠지요. 당근.

neon20의 이미지

코딩에서 실수가 있었네요.. :oops: 그런데..

int A(){
struct timeval mytime;

gettimeofday(&mytime,NULL);
return mytime.tv_usec;
}

int a,b;

a = A();
b = A();

위와같이 A를 두번 호출했을때 a,b가 갖게되는 값의 의미는 뭔가요? gettimeofday 호출을 통해서 프로그램 수행시간을 알아보려고 하는데 리턴되는 값의 의미를 모르겠습니다.. :cry:

익명 사용자의 이미지

음 위와 같이 구하면 아니되옵니다.
연산하는데 시간을 구하려면, 보통 다음과 같이 만듭니다.

gettimeofday(&tv1, NULL);
// 무엇인가? 연산하는 프로그램.
...
gettimeofday(&tv2, NULL);
dt = (tv2.tv_sec-tv1.tv_sec)*1000000+(tv2.tv_usec-tv1.tv_usec);
익명사용자의 이미지

dt = (tv2.tv_sec-tv1.tv_sec)*1000000+(tv2.tv_usec-tv1.tv_usec);
dt = (tv2.tv_sec-tv1.tv_sec)+(tv2.tv_usec-tv1.tv_usec)*1000000;

익명 사용자의 이미지

에구, 보통 연산(처리,프로세싱, 응답시간등)하는데 걸리는 시간을 측정할때
사용하지요.
특정 연산시작하기전 시간구하고, 끝난 직후 시간을 구해 빼서, 그 차이로
얼마의 시간이 걸렸나?를 구하는데 사용됩니다.
elapsed time이라고 보통 부르지요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.