Java和Golang对比


本文摘自网络,作者,侵删。

package com.main;

import cn.hutool.core.date.DateUtil;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {




    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        long now = DateUtil.current(true);

        System.out.println("开始执行时间:" +  now);

        executorService.submit(Test::loopHello);

        long now2 = DateUtil.current(true);
        System.out.println("结束执行时间:" +  now2);
        System.out.println("总执行时间:" + (now2 - now));

    }

    private static void loopHello() {
        var i=0;
        while (i< 1000000000) {
            i++;
            sayHello();
        }
    }

    private static Integer sayHello() {
        var b = 1;
        var a = 22;
        return a + b;
    }

}


开始执行时间:264803974827800
结束执行时间:264804026950899
总执行时间:52123099
package main

import (
    "fmt"
    "time"
)

func sayHello() int {
    b := 1
    a := 22
    c := a + b
    return c
}

func loopHello() {
    var i=0
    for i<1000000000 {
        i++
        sayHello()
    }
}

func main() {
    nanosecond := time.Now().Nanosecond()
    fmt.Println("开始执行时间:", nanosecond)

    go loopHello()

    i2 := time.Now().Nanosecond()

    fmt.Println("结束执行时间:", i2)

    fmt.Println("总执行时间:", i2 - nanosecond)


}

开始执行时间: 558146100
结束执行时间: 558146100
总执行时间: 0

本文来自:简书

感谢作者:_Charmy

查看原文:Java和Golang对比

相关阅读 >>

Golang 归并排序

Gocn酷Go推荐】Go程序配置利器-viper库

redis Go语言与redis数据库交互

Go从学会到学废】(零) Golang简介

Go是动态语言还是静态语言

Go是强类型语言么

Golang 面向对象编程

Golang怎么编译

手撸Golang 行为型设计模式 备忘录模式

Golang 免费的吗?

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...