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

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

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++性能
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

14 条评论

  1. <a href="http://www.daddeaze.com/converse-femme-all-star-blanche-shoesz">converse femme all star blanche</a> <a href="http://www.debracousins.com/nike-dam%C3%A4nner-free-5.0-schuhe-ho14-schuheb">nike dam盲nner free 5.0 schuhe ho14</a> <a href="http://www.yankaripark.com/denver-broncos-gary-zimmerman-navy-blue-nike-65-nfl-long-sleeve-t-shirt-name-number-logo-nflu">denver broncos gary zimmerman navy blue nike 65 nfl long sleeve t shirt name number logo</a> <a href="http://www.yicailottery.com/adidas-tubular-x-primeknit-core-black-skou">adidas tubular x primeknit core black</a> <a href="http://www.calebcraw.com/air-jordan-11-real-december-21-runningf">air jordan 11 real december 21</a> <a href="http://www.liquidputter.com/new-balance-white-shoes-philippines-zapatosu">new balance white shoes philippines</a>
    rpnailsalon http://www.rpnailsalon.com/

  2. <a href="http://www.flushnhunt.com/kvinders-asics-gel-hyper-33-gr%C3%B8n-hvid-skoh">kvinders asics gel hyper 33 gr酶n hvid</a> <a href="http://www.evelpa.com/hommes-nike-free-tr-fit-noir-blanc-chaussuresh">hommes nike free tr fit noir blanc</a> <a href="http://www.taaliminfos.com/butler-bulldogs-47-ncaa-47-clean-up-cap-hatl">butler bulldogs 47 ncaa 47 clean up cap</a> <a href="http://www.cacikvideo.com/hommes-nike-air-max-noir-gris-chaussuresh">hommes nike air max noir gris</a> <a href="http://www.grossavind.com/mujeres-nike-lunarglide-7-verde-negro-zapatosk">mujeres nike lunarglide 7 verde negro</a> <a href="http://www.boltsfans.com/nike-air-max-mens-pink-shoesi">nike air max mens pink</a>
    genievres http://www.genievres.com/

  3. <a href="http://www.epackproject.com/hvid-and-gr%C3%B8n-jordan-9-butyc">hvid and gr酶n jordan 9</a> <a href="http://www.flashuse.com/nike-air-max-90-negro-rojo-blanco-butye">nike air max 90 negro rojo blanco</a> <a href="http://www.airtestuser.com/curry-3-low-oro-kurpesd">curry 3 low oro</a> <a href="http://www.bajigour.com/kyrie-2-cool-grigio-full-movie-schuhea">kyrie 2 cool grigio full movie</a> <a href="http://www.calaforracs.com/nike-air-max-97-marrone-gun-kurpesf">nike air max 97 marrone gun</a> <a href="http://www.clboaiyy.com/ua-clutchfit-drive-hvit-gr%C3%B8nn-chaussuresa">ua clutchfit drive hvit gr酶nn</a>
    bladespares http://www.bladespares.com/

  4. avatar fetison

    <a href="http://www.agichipay.com/nike-tri-fusion-run-msl-womens-purple-orange-trainersa">nike tri fusion run msl womens purple orange</a> <a href="http://www.millsbulb.com/air-max-97-argento-fuori-produzione-scarpec">air max 97 argento fuori produzione</a> <a href="http://www.hamshrd.com/nike-air-yeezy-2-svart-solar-r%C3%B8d-for-salg-va-kurpesd">nike air yeezy 2 svart solar r酶d for salg va</a> <a href="http://www.lroyroofing.com/oakley-crosslink-sunglasses-template-for-kids-sunglassesg">oakley crosslink sunglasses template for kids</a> <a href="http://www.golfbodyshop.com/womens-jimmie-ward-green-jersey-elite-salute-to-service-nike-nfl-san-francisco-49ers-20-nflr">womens jimmie ward green jersey elite salute to service nike nfl san francisco 49ers 20</a> <a href="http://www.yufnsyb.com/air-jordan-phase-23-classic-mens-white-grey-skoa">air jordan phase 23 classic mens white grey</a>
    fetison http://www.fetison.com/

  5. avatar atppest

    <a href="http://www.myfraimz.com/elite-jacoby-jones-jersey-baltimore-ravens-12-team-road-two-tone-nfle">elite jacoby jones jersey baltimore ravens 12 team road two tone</a> <a href="http://www.winnercells.com/purple-green-mens-nike-zoom-terra-kiger-shoes-runningf">purple green mens nike zoom terra kiger shoes</a> <a href="http://www.atppest.com/women-2012-new-nfl-jerseys-san-francisco-49ers-53-navorro-bowman-red-jerseys-hall-of-fames-50th-patch-nflv">women 2012 new nfl jerseys san francisco 49ers 53 navorro bowman red jerseys hall of fames 50th patch</a> <a href="http://www.windriftbar.com/nike-air-presto-womens-blue-red-trainersa">nike air presto womens blue red</a> <a href="http://www.kidtokidboise.com/nero-baby-blu-jordan-14-scarped">nero baby blu jordan 14</a> <a href="http://www.mesmertronic.com/new-blance-996-ni%C3%B1os-p%C3%BArpura-gris-kurpesd">new blance 996 ni帽os p煤rpura gris</a>
    atppest http://www.atppest.com/

  6. avatar urevomedia

    <a href="http://www.teamoxia.com/air-jordan-cp3-white-grey-skoc">air jordan cp3 white grey</a> <a href="http://www.kinkyfresno.com/nike-sb-portmore-menns-bl%C3%A5-skob">nike sb portmore menns bl氓</a> <a href="http://www.myoastudies.com/adidas-superstar-2-light-blau-shoesv">adidas superstar 2 light blau</a> <a href="http://www.kinkfresno.com/gold-pink-womens-nike-kwazi-action-shoes-runninga">gold pink womens nike kwazi action shoes</a> <a href="http://www.achievehacks.com/oakley-holbrook-sunglasses-julian-wilson-sunglassesr">oakley holbrook sunglasses julian wilson</a> <a href="http://www.singingtoons.com/reebok-gl-6000-white-shoesv">reebok gl 6000 white</a>
    urevomedia http://www.urevomedia.com/

  7. avatar truckent

    <a href="http://www.javlust.com/nike-kobe-9-low-kvinders-orange-r%C3%B8d-obuvb">nike kobe 9 low kvinders orange r酶d</a> <a href="http://www.postmatespro.com/nike-dunk-low-campus-wei%C3%9F-grau-schwarz-butya">nike dunk low campus wei脽 grau schwarz</a> <a href="http://www.uilstrategie.com/nike-mens-frank-ragnow-limited-black-jersey-detroit-lions-nfl-77-rush-vapor-untouchable-nflu">nike mens frank ragnow limited black jersey detroit lions nfl 77 rush vapor untouchable</a> <a href="http://www.youtubetune.com/nike-internationalist-sunset-tint-cool-grau-schwarz-kurpesb">nike internationalist sunset tint cool grau schwarz</a> <a href="http://www.carbonstalk.com/adidas-tubular-runner-rojo-cielo-azul-schuhec">adidas tubular runner rojo cielo azul</a> <a href="http://www.gospeedbird.com/dam%C3%A4nner-air-jordan-retro-1-blau-schwarz-schuheg">dam盲nner air jordan retro 1 blau schwarz</a>
    truckent http://www.truckent.com/

  8. avatar mushigiftpack

    <a href="http://www.ntygadget.com/nike-shoes-2016-mens-silver-grey-skoa">nike shoes 2016 mens silver grey</a> <a href="http://www.purchasetulsa.com/adidas-climacool-ride-v-white-pink-sneakere">adidas climacool ride v white pink</a> <a href="http://www.pennywave.com/yeezy-boost-950-bon-march%C3%A9-hotel-kurpesa">yeezy boost 950 bon march茅 hotel</a> <a href="http://www.scoptix.com/nike-air-max-2016-black-orange-yellow-sneakerb">nike air max 2016 black orange yellow</a> <a href="http://www.domodrzwi.com/nike-kd-10-womens-green-yellow-shoesg">nike kd 10 womens green yellow</a> <a href="http://www.magneticduo.com/jordan-dad-hat-hats">jordan dad hat</a>
    mushigiftpack http://www.mushigiftpack.com/

  9. avatar jw29vy17

    <a href="http://www.jw29vy17.com/nike-kobe-basketbtutti-scarpe-butya">nike kobe basketbtutti scarpe</a> <a href="http://www.zkjl97o1.com/nike-air-max-90-infrarouge-flyknit-lunar-3-obuvb">nike air max 90 infrarouge flyknit lunar 3</a> <a href="http://www.jc994clo.com/air-jordan-cp3-oro-argento-scarpec">air jordan cp3 oro argento</a> <a href="http://www.eu40ezhg.com/adidas-ultra-boost-herren-laufen-schuhe-marine-schuhef">adidas ultra boost herren laufen schuhe marine</a> <a href="http://www.zs007uke.com/air-jordan-17-vert-blanc-scarpeb">air jordan 17 vert blanc</a> <a href="http://www.f509ceic.com/nike-mercurial-superfly-dark-gr%C3%A5-walls-schuhee">nike mercurial superfly dark gr氓 walls</a>
    jw29vy17 http://www.jw29vy17.com/

  10. avatar barrettmark

    <a href="http://www.terrystorar.com/adidas-nmd-runner-hvid-sko-sort-chaussuresd">adidas nmd runner hvid sko sort</a> <a href="http://www.lahjeh.com/curry-3-herren-schuhe-obuve">curry 3 herren schuhe</a> <a href="http://www.hugxpetdesign.com/jordan-11-gamma-bl%C3%A5-hvid-kurpesd">jordan 11 gamma bl氓 hvid</a> <a href="http://www.cenadeeventos.com/nike-air-force-1-bespoke-for-salg-schuhec">nike air force 1 bespoke for salg</a> <a href="http://www.jeangodbout.com/nike-cortez-gull-and-svart-hair-butyg">nike cortez gull and svart hair</a> <a href="http://www.iamsamcollier.com/air-max-90-hyperfuse-for-vendita-uk-scarped">air max 90 hyperfuse for vendita uk</a>
    barrettmark http://www.barrettmark.com/

  11. 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/

  12. 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/

  13. 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]

  14. 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