C#
{
static void Main(string[] args)
{
TestPerformance();
Console.ReadKey();
}
static void TestPerformance()
{
long num = 500000000;
long count = 0;
DateTime _startTime = DateTime.UtcNow;
Console.WriteLine(_startTime.ToString());
for(int i=0;i<num;i++)
{
if(i%2==0)
{
count++;
}
}
DateTime _endTime = DateTime.UtcNow;
Console.WriteLine(_endTime.ToString());
Console.WriteLine("Process Loop:"+count+",Spend Mill Seconds: "+(_endTime-_startTime).TotalMilliseconds);
}
}
# 运行于netcore,1154毫秒
#2019/4/30 8:38:47
#2019/4/30 8:38:48
#Process Loop:250000000,Spend Mill Seconds: 1154.9266
Go
package main
import "time"
import "fmt"
func main(){
TestPerformance()
}
func TestPerformance(){
var num,count,i int64
num=500000000
//fmt.Println(time.Now())
st:=time.Now().UnixNano()/1e6
fmt.Println(st)
for i=0;i<num;i++{
if 1%2==0{
count++;
}
}
//fmt.Println(time.Now())
et:=time.Now().UnixNano()/1e6
fmt.Println(et)
fmt.Println((et-st))
}
#go 结果
#1556613847488
#1556613847612
#124
go相较C#快十倍
C# DateTime与时间戳转换(https://www.cnblogs.com/polk6/p/6024892.html)
JavaScript时间戳:是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总毫秒数。
Unix时间戳:是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
Golang的time包:秒、毫秒、纳秒时间戳输出(https://blog.csdn.net/mirage003/article/details/80822608)
10位数的时间戳是以 秒 为单位;13位数的时间戳是以 毫秒 为单位;19位数的时间戳是以 纳秒 为单位;
golang中可以这样写:
package main
import (
"time"
"fmt"
)
func main() {
fmt.Printf("时间戳(秒):%v;\n", time.Now().Unix())
fmt.Printf("时间戳(纳秒):%v;\n",time.Now().UnixNano())
fmt.Printf("时间戳(毫秒):%v;\n",time.Now().UnixNano() / 1e6)
fmt.Printf("时间戳(纳秒转换为秒):%v;\n",time.Now().UnixNano() / 1e9)
}
#输出结果为:
#时间戳(秒):1530027865;
#时间戳(纳秒):1530027865231834600;
#时间戳(毫秒):1530027865231;
#时间戳(纳秒转换为秒):1530027865;