Linux下C++语言统计一段逻辑处理耗费时间的方法

2015年04月28日 其他资源 4条评论 阅读3617次

Linux下C++语言统计一段逻辑处理耗费时间的方法

Linux下C++语言计算一段逻辑处理耗费时间的方法[微妙级]

有一段逻辑处理,想要知道它所消耗的时间用以计算性能,所以要在处理开始前,处理结束后分别取时间来计算中间处理消耗的时间。

考虑到C++本身的高性能,一般的逻辑耗时也不会太多,所以这时我们希望计算的处理时间能够精确到微妙级别。

struct timeval start, end, diff;

gettimeofday(&start, 0);

// your logic

// ......

gettimeofday(&end, 0);

int nsec;

diff.tv_sec = ( end.tv_sec - start.tv_sec );

diff.tv_usec = ( end.tv_usec - start.tv_usec );

if (diff.tv_usec < 0)

{

    diff.tv_sec--;

    diff.tv_usec += 1000000;

}

int usec = diff.tv_usec + diff.tv_sec * 100000;

printf("logic used time %d(us)", usec);

分享本文至:

WRITTEN BY

avatar
本文标签:C++性能
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

4 条评论

  1. avatar governisation

    <a href="http://www.dragongateusa.com/nike-dunk-black-gum-trainersa">nike dunk black gum</a> <a href="http://www.tarabzouni.com/air-jordan-5-retro-colorway-costume-skoe">air jordan 5 retro colorway costume</a> <a href="http://www.aurelmar.com/nike-cortez-red-white-blue-yellow-skoc">nike cortez red white blue yellow</a> <a href="http://www.rivacover.com/bon-march%C3%A9-nike-air-max-2011-femmes-blanc-shoesc">bon march茅 nike air max 2011 femmes blanc</a> <a href="http://www.annanilsen.com/pink-green-mens-nike-dunk-shoes-trainersb">pink green mens nike dunk shoes</a> <a href="http://www.fhomestudio.com/nike-lebron-13-herren-orange-skob">nike lebron 13 herren orange</a>
    governisation http://www.governisation.com/

  2. avatar leesgoedplus

    <a href="http://www.kosarkomur.com/nike-kobe-10-5am-custom-sportsb">nike kobe 10 5am custom</a> <a href="http://www.plakglas.com/yeezy-750-boost-low-mood-trainerse">yeezy 750 boost low mood</a> <a href="http://www.quaderealty.com/t%C3%AAnis-nike-shox-nz-eu-masculino-skor">t锚nis nike shox nz eu masculino</a> <a href="http://www.captmollie.com/jj-watt-jersey-nfl-shop-nflr">jj watt jersey nfl shop</a> <a href="http://www.thermilax.com/oakland-raiders-15-michael-crabtree-olive-2017-salute-to-service-limited-jersey-nflv">oakland raiders 15 michael crabtree olive 2017 salute to service limited jersey</a> <a href="http://www.ladivorcecpa.com/ralph-lauren-white-rugby-shirt-polor">ralph lauren white rugby shirt</a>
    leesgoedplus http://www.leesgoedplus.com/

  3. avatar hobbyfreaks

    <a href="http://www.gladatassen.com/prada-messenger-purse-keeper-pradab">prada messenger purse keeper</a> <a href="http://www.strongtowercf.com/mulberry-bag-strap-for-sale-canada-mulberrye">mulberry bag strap for sale canada</a> <a href="http://www.hamiltonhunt.com/nike-air-huarache-light-dam%C3%A4nner-gelb-sneakerd">nike air huarache light dam盲nner gelb</a> <a href="http://www.mailstraight.com/hermes-kelly-grey-hermesr">hermes kelly grey</a> <a href="http://www.kmkonka.com/nike-air-force-1-puerto-rico-sko-shoesv">nike air force 1 puerto rico sko</a> <a href="http://www.todayjosh.com/purple-coach-bag-coacha">purple coach bag</a>
    [url=http://www.hobbyfreaks.com/]hobbyfreaks[/url]

  4. avatar boluposter

    <a href="http://www.agentshooter.com/is-my-ferragamo-belt-real-beltr">is my ferragamo belt real</a> <a href="http://www.chachiscoffee.com/women-mackage-pant-rack-wood-mackagec">women mackage pant rack wood</a> <a href="http://www.ubcfellowship.com/nike-kaishi-blue-skow">nike kaishi blue</a> <a href="http://www.financewarm.com/nba-jerseys-san-antonio-spurs-21-tim-duncan-black-leopard-grain-jerseys-nflc">nba jerseys san antonio spurs 21 tim duncan black leopard grain jerseys</a> <a href="http://www.baktindo.com/washington-wizards-gold-jersey-nflr">washington wizards gold jersey</a> <a href="http://www.waterlowcards.com/bon-march%C3%A9-nike-air-max-87-femmes-or-foote">bon march茅 nike air max 87 femmes or</a>
    boluposter http://www.boluposter.com/

欢迎留言




用户登录

sitemap