您的位置 首页 golang

对比看下golang强大的运算速度

 package main

import (
"fmt"
"math/rand"
" runtime "
"time"
)

func main() {
runtime.GC()

start := time.Now().UnixNano() / 1e6 //毫秒数
sum := 0
kk := GenerateRandnum(3)
max := 100000000 + kk
for i := 0; i < max; i++ {
sum = sum + kk
}

fmt.Println(time.Now().UnixNano()/1e6 - start) //毫秒数
fmt.Println(sum)
fmt.Println(max)
}
func GenerateRandnum(k int) int {
rand.Seed(time.Now().Unix())
randNum := rand.Intn(k)
return randNum
}

//结果只要30-40毫秒,多次测试差别不大  
对比看下golang强大的运算速度

再对比下 delphi 运行速度,delphi号称有接近于c++的速度。

 procedure TForm1.Button1Click(Sender: TObject);
var i,t,sum,kk,max1:Int64;
begin
  t:=GetTickCount;
  Randomize;
  kk:=Random(3);
  sum:=0;
  for I := 0 to 100000000+kk do
  begin
     sum:=sum+kk;
  end;

  t:=GetTickCount-t;
  ShowMessagefmt('%d,%d',[t,sum]);
end;
//  
对比看下golang强大的运算速度

以上两个测试,使用了动态种子生成的随机数,随机次数多加了几次,每次加的也不是固定1
避免了编译器优化。本机普通电脑win7 x64电脑测试了很多次差别不大。

golang的速度在30-40毫秒之间

delphi的速度在280-290之间。

多轮测试差别不大。

这样的对比速度简直让人惊喜,delphi作为静态编译语言,优化已经做得很好了,golang竟然有这样快了么?

文章来源:智云一二三科技

文章标题:对比看下golang强大的运算速度

文章地址:https://www.zhihuclub.com/89007.shtml

关于作者: 智云科技

热门文章

评论已关闭

34条评论

  1. They found that p16, PTEN, and IMP3 were statistically significantly more frequently expressed in SC in comparison with EEC3, whereas ER and p53 approached but did not reach significance A, B Retinal thickness and lamination was evaluated in vivo using optical coherence tomography OCT; 1

  2. In the future, any insurance hospital that was taken away CBD hemp oil in Canada Londoners who are not afraid of people are starting to be afraid

  3. Meanwhile, ERО± can also promote the CXCL11 secretion of cancer cells and activate EMT induced by CXCR7 127

  4. levitra glimepiride brand name in pakistan Гў Follow up time was calculated from the date of risk reducing salpingo oophorectomy to the date of hysterectomy, histopathological diagnosis of endometrial cancer or date of death, whichever occurred first; the data for women who were alive without endometrial cancer or hysterectomy were censored as the date of their last assessment at the Family Cancer Clinic, plus 1 year

  5. You have managed to INCREASE anabolism Test levels and DECREASE catabolism cortisone, during a bridge to boot

  6. 2011 Apr; 23 Suppl S3 9 Coenzyme Q10 and coronary artery bypass surgery what we have learned from clinical trials

  7. If possible, learn to take a respiratory breathing rate when your cat is resting ask your vet about this

  8. Elwood CuPjHcPKyf 6 18 2022 6 mL 100mL Kit Ophthalmic; Oral; Topical Honeywell Safety Products USA, Inc 2018 10 18 Not applicable US 4022 First Aid Kit Acetaminophen 325 mg 1 Benzalkonium chloride 0

  9. Chemical nature of hormones fragilis or other penicillin resistant anaerobic bacteria, it has lost favor as an empirical agent for polymicrobial intraabdominal infections

  10. Hello everyone I think that this form will be very helpful for all that are on Clomid or that will start Clomid soon The following three typical patterns of response were observed 1 decrease in cell numbers 10 fold; 2 marginal changes in cell numbers 10 fold in numbers of CETCs

  11. Conjugated linoleic acid inhibits proliferation and induces apoptosis of normal rat mammary epithelial cells in primary culture Endometriosis was documented on the basis of evidence of this condition at laparoscopy or laparotomy

  12. Whey represents the bulk of the amino acid content in protein, accounting for around 95 of protein in the human diet, best peptides to increase testosterone

  13. These local projection patterns are consistent with the canonical feedforward pathways within a cortical column observed in somatosensory and visual cortices, with the first feedforward step from L4 to L2 3 and the second feedforward step from L2 3 to L5 67

  14. pentobarbital will decrease the level or effect of nicardipine by affecting hepatic intestinal enzyme CYP3A4 metabolism

  15. I know I can still O, but I wish I could feel like it is working a little trimipramine and ziconotide both increase sedation

  16. Our national survey in 2001 indicated that 268 of 854 31 of gynaecologists performing uterine polypectomy were supportive of a trial comparing inpatient with outpatient uterine polypectomy

  17. Gentamicin Injection Gentamicin Injection Gentamicin may decrease the excretion rate of Enzalutamide which could result in a higher serum level

  18. com 20 E2 AD 90 20A 20Que 20Edad 20Empiezan 20A 20Tomar 20Viagra 20 20Viagra 20Connect 20Near 20Me viagra connect near me LVMH rival Kering on said on Thursday the slowdown continuedin China but earlier this week Swatch Group, theworld s biggest watch maker, said it expected Chinese demand toimprove in the second half

网站地图