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

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

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.flypiip.com/mens-asics-gel-noosa-tri-10-orange-purple-footc">mens asics gel noosa tri 10 orange purple</a> <a href="http://www.frissedenkers.com/tory-burch-boots-size-8-toryburchr">tory burch boots size 8</a> <a href="http://www.brbuyeragent.com/air-jordan-11-marr%C3%B3n-rojo-butyf">air jordan 11 marr贸n rojo</a> <a href="http://www.edenwins.com/jordan-6-infrarouge-champs-obuve">jordan 6 infrarouge champs</a> <a href="http://www.ceespeters.com/ua-clutchfit-prodigy-verde-rojo-obuvc">ua clutchfit prodigy verde rojo</a> <a href="http://www.fitwizhawaii.com/ralph-lauren-polo-shirts-nordstrom-hours-poloa">ralph lauren polo shirts nordstrom hours</a>
    sphygmic http://www.sphygmic.com/

  2. <a href="http://www.whatiownapp.com/air-jordan-phase-azul-verde-scarpee">air jordan phase azul verde</a> <a href="http://www.veronafabric.com/vestidos-florales-en-invierno-dresse">vestidos florales en invierno</a> <a href="http://www.votejohndavis.com/dam%C3%A4nner-air-max-90-em-blau-rosa-footc">dam盲nner air max 90 em blau rosa</a> <a href="http://www.stillbaymotel.com/nike-hypervenomx-finale-phylon-indoor-soccer-zapatos-liquid-oro-negro-butym">nike hypervenomx finale phylon indoor soccer zapatos liquid oro negro</a> <a href="http://www.ecosphereasi.com/parajumpers-jacket-jumper-air-parajumpersb">parajumpers jacket jumper air</a> <a href="http://www.dacsud.com/canada-goose-expedition-parka-deutschland-outlet-canadagooseb">canada goose expedition parka deutschland outlet</a>
    caraweston http://www.caraweston.com/

  3. <a href="http://www.anilmm.com/nike-lebron-13-rot-gelb-scarpee">nike lebron 13 rot gelb</a> <a href="http://www.fmfsigorta.com/blumenhochzeits-kleid-f%C3%BCr-verkauf-dresse">blumenhochzeits kleid f眉r verkauf</a> <a href="http://www.roywilhite.com/nike-sock-dart-sp-rose-footc">nike sock dart sp rose</a> <a href="http://www.acductwork.com/air-jordan-jumpman-team-s%C3%B8lv-bl%C3%A5-butym">air jordan jumpman team s酶lv bl氓</a> <a href="http://www.corsportinc.com/parajumpers-gobi-eco-men-outerwear-sage-parajumpersb">parajumpers gobi eco men outerwear sage</a> <a href="http://www.phramaha.com/canada-goose-jacket-outlet-sale-store-victoria-canadagooseb">canada goose jacket outlet sale store victoria</a>
    ricusiowo http://www.ricusiowo.com/

  4. avatar fmpfinc

    <a href="http://www.designnewsnow.com/air-jordan-retro-2-blanc-vert-trainersd">air jordan retro 2 blanc vert</a> <a href="http://www.baronvelocity.com/nike-shox-deliver-toddler-l%C3%B8b-sko-chaussuresm">nike shox deliver toddler l酶b sko</a> <a href="http://www.diannewright.com/femminile-long-sleeve-pique-polo-shirts-poloa">femminile long sleeve pique polo shirts</a> <a href="http://www.itsmykarate.com/herren-nike-free-run-2-rot-wei%C3%9F-scarpek">herren nike free run 2 rot wei脽</a> <a href="http://www.proseccoshow.com/que-collar-usar-con-un-vestido-floral-dresse">que collar usar con un vestido floral</a> <a href="http://www.automatiktor.com/adidas-nmd-runner-marine-hair-footi">adidas nmd runner marine hair</a>
    fmpfinc http://www.fmpfinc.com/

  5. avatar dciphone

    <a href="http://www.domegutter.com/parajumpers-vest-looks-awesome-parajumpersa">parajumpers vest looks awesome</a> <a href="http://www.motykare.com/moncler-mens-spring-jackets-australia-monclera">moncler mens spring jackets australia</a> <a href="http://www.curlywoodwind.com/air-max-90-sneakerboot-challenge-r%C3%B8d-chaussuresb">air max 90 sneakerboot challenge r酶d</a> <a href="http://www.narrateblog.com/nike-flyknit-lunar-1-volt-noir-hypervenoms-zapatosj">nike flyknit lunar 1 volt noir hypervenoms</a> <a href="http://www.ronjaespejord.com/lebron-13-amarillo-rice-obuvf">lebron 13 amarillo rice</a> <a href="http://www.cjcoffrin.com/pandora-charms-uk-gumtree-for-sale-pandoraj">pandora charms uk gumtree for sale</a>
    dciphone http://www.dciphone.com/

  6. avatar ceespeters

    <a href="http://www.maracamp.com/nike-air-huarache-ultra-fl%C3%A5den-obuvb">nike air huarache ultra fl氓den</a> <a href="http://www.offleaseford.com/nike-kd-gelb-braun-butya">nike kd gelb braun</a> <a href="http://www.suncreamclub.com/tory-burch-ballet-flats-nordstrom-toryburchr">tory burch ballet flats nordstrom</a> <a href="http://www.alusownia.com/nobis-jacket-weather-uk-nobisb">nobis jacket weather uk</a> <a href="http://www.breachurch.com/mackage-jacket-winnipeg-mackager">mackage jacket winnipeg</a> <a href="http://www.janetsher.com/nike-mennns-lunar-superbad-pro-detachable-football-cleats-kurpese">nike mennns lunar superbad pro detachable football cleats</a>
    ceespeters http://www.ceespeters.com/

  7. avatar florantalya

    <a href="http://www.vdart.net/nike-kd-9-r%C3%B8d-and-hvit-vin-obuve">nike kd 9 r酶d and hvit vin</a> <a href="http://www.ventarium.net/maschio-air-max-90-hyperfuse-verde-grigio-schuhee">maschio air max 90 hyperfuse verde grigio</a> <a href="http://www.villacafaggio.net/nike-air-max-95-infrarouge-manual-kurpesc">nike air max 95 infrarouge manual</a> <a href="http://www.vipervaporcheck.net/mujeres-nike-air-max-2015-p%C3%BArpura-rojo-butyf">mujeres nike air max 2015 p煤rpura rojo</a> <a href="http://www.visitojaica.net/nike-flynit-air-max-femmes-or-rose-scarpee">nike flynit air max femmes or rose</a> <a href="http://www.vivaeuropa.net/air-jordan-future-royal-mail-schuhea">air jordan future royal mail</a>
    florantalya http://www.florantalya.net/

  8. avatar trianglescion

    <a href="http://www.realchiyouth.com/new-york-mets-grey-jersey-nflh">new york mets grey jersey</a> <a href="http://www.djhomeimprove.com/adidas-ultra-boost-laufschuh-blanco-multicolor-zapatosh">adidas ultra boost laufschuh blanco multicolor</a> <a href="http://www.mybigrefund.com/nike-free-3.0-flyknit-rouge-scarpea">nike free 3.0 flyknit rouge</a> <a href="http://www.gamesiamfree.com/florida-gators-47-ncaa-kids-basic-47-mvp-cap-hati">florida gators 47 ncaa kids basic 47 mvp cap</a> <a href="http://www.cavechezludo.com/kvinders-nike-blazer-hvid-gr%C3%A5-trainersb">kvinders nike blazer hvid gr氓</a> <a href="http://www.rxmedsuk.com/herre-asics-gel-noosa-tri-8-bl%C3%A5-kurpesd">herre asics gel noosa tri 8 bl氓</a>
    trianglescion http://www.trianglescion.com/

  9. avatar begichbaggage

    <a href="http://www.davidtraina.com/billig-nike-free-nr-dam%C3%A4nner-lila-sportsd">billig nike free nr dam盲nner lila</a> <a href="http://www.landvoicepro.com/asics-gel-lyte-5-purple-blue-shoesc">asics gel lyte 5 purple blue</a> <a href="http://www.zipperdude.com/nike-flyknit-lunar-3-for-verkauf-georgia-schuhef">nike flyknit lunar 3 for verkauf georgia</a> <a href="http://www.karlcoates.com/unisex-nike-roshe-two-bianca-argento-kurpesc">unisex nike roshe two bianca argento</a> <a href="http://www.cloisonnes.com/adidas-mundial-goal-maize-zapatosu">adidas mundial goal maize</a> <a href="http://www.orsadonna.com/limited-youth-sammie-coates-navy-blue-jersey-nfl-nike-houston-texans-18-therma-long-sleeve-nflt">limited youth sammie coates navy blue jersey nfl nike houston texans 18 therma long sleeve</a>
    begichbaggage http://www.begichbaggage.com/

  10. avatar avonbeads

    <a href="http://www.bluesophy.com/greg-olsen-jersey-shirt-nflh">greg olsen jersey shirt</a> <a href="http://www.stylehousestl.com/adidas-ace-16-oro-and-blanco-zapatosh">adidas ace 16 oro and blanco</a> <a href="http://www.byvergara.com/kvinners-nike-zoom-structure-18-all-hvit-scarpea">kvinners nike zoom structure 18 all hvit</a> <a href="http://www.ruthlesscrew.com/washington-state-cougars-nike-ncaa-classic-swoosh-cap-hati">washington state cougars nike ncaa classic swoosh cap</a> <a href="http://www.fullserviceap.com/nike-zoom-train-action-gris-noir-trainersb">nike zoom train action gris noir</a> <a href="http://www.idealkizlar.com/herren-nike-roshe-run-hyp-orange-gr%C3%BCn-kurpesd">herren nike roshe run hyp orange gr眉n</a>
    avonbeads http://www.avonbeads.com/

  11. avatar drpfanstiel

    <a href="http://www.bazicloob.com/nike-air-max-90-hyperfuse-fluorescent-green-shoesk">nike air max 90 hyperfuse fluorescent green</a> <a href="http://www.malatyabolge.com/adidas-climacool-ride-ii-menn-svart-oransje-obuvi">adidas climacool ride ii menn svart oransje</a> <a href="http://www.impeachjohn.com/nike-blazer-high-hvit-r%C3%B8d-obuvk">nike blazer high hvit r酶d</a> <a href="http://www.dafuqstory.com/nike-free-run-2-rosa-and-gr%C3%A5-obuvi">nike free run 2 rosa and gr氓</a> <a href="http://www.liberezmoi.com/hombres-air-foamposite-one-blanco-negro-gris-zapatosl">hombres air foamposite one blanco negro gris</a> <a href="http://www.scrutinit.com/nero-bandana-nike-cortez-scarpeh">nero bandana nike cortez</a>
    drpfanstiel http://www.drpfanstiel.com/

  12. avatar coachpsy

    <a href="http://www.trancelater.net/nike-roshe-two-triple-nero-kurpesc">nike roshe two triple nero</a> <a href="http://www.uscampvictory.net/reebok-insta-pump-fury-wei%C3%9F-gold-schuhea">reebok insta pump fury wei脽 gold</a> <a href="http://www.veetracker.net/air-jordan-retro-8-negro-naranja-marmalade-kurpesf">air jordan retro 8 negro naranja marmalade</a> <a href="http://www.velomini.net/ua-clutchfit-prodigy-silber-chaussuresa">ua clutchfit prodigy silber</a> <a href="http://www.voilahalla.net/adidas-john-wtodas-verde-inferno-kurpesg">adidas john wtodas verde inferno</a> <a href="http://www.walterinsurance.net/nike-free-run-2-schwarz-metalleic-silber-lab-schuhee">nike free run 2 schwarz metalleic silber lab</a>
    coachpsy http://www.coachpsy.net/

  13. avatar keleric

    <a href="http://www.koreazp.com/womens-nike-lunarglide-7-gold-orange-shoesi">womens nike lunarglide 7 gold orange</a> <a href="http://www.hiltonskyshop.com/nike-kobe-5-yellow-red-shoesp">nike kobe 5 yellow red</a> <a href="http://www.lavaforchange.com/air-jordan-b-mo-rosa-lilla-obuvl">air jordan b mo rosa lilla</a> <a href="http://www.lifeonfilms.com/air-jordan-phase-mintgr%C3%B8n-gr%C3%A5-skoj">air jordan phase mintgr酶n gr氓</a> <a href="http://www.midlandroofer.com/femminile-nike-air-max-tailwind-6-blu-oro-scarpel">femminile nike air max tailwind 6 blu oro</a> <a href="http://www.pearsonchool.com/womens-asics-gel-noosa-tri-8-yellow-white-shoesj">womens asics gel noosa tri 8 yellow white</a>
    [url=http://www.keleric.com/]keleric[/url]

  14. avatar transonellc

    <a href="http://www.joshuaarens.com/maschio-nike-air-huarache-bianca-verde-butyg">maschio nike air huarache bianca verde</a> <a href="http://www.jschwimmermd.com/youth-nike-new-york-jets-51-brandon-copeland-limited-black-2016-salute-to-service-nfl-jersey-nflx">youth nike new york jets 51 brandon copeland limited black 2016 salute to service nfl jersey</a> <a href="http://www.markedtreear.com/air-jordan-retro-9-gamma-azul-butyd">air jordan retro 9 gamma azul</a> <a href="http://www.mauigrub.com/nike-free-5.0-femmes-noir-gray-kurpesc">nike free 5.0 femmes noir gray</a> <a href="http://www.mgnmilitaria.com/ralph-lauren-shirt-polo-wei%C3%9F-in-slim-fit-m%C3%A4nner-cotton-twill-polos">ralph lauren shirt polo wei脽 in slim fit m盲nner cotton twill</a> <a href="http://www.nanainchief.com/mujeres-nike-air-huarache-light-butyf">mujeres nike air huarache light</a>
    transonellc http://www.transonellc.com/

欢迎留言




用户登录

sitemap