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