package com.xgp.company;
public class Main {
private static int count = 0;
public static void main(String[] args) {
long start = System.currentTimeMillis();
// System.out.println(start);
for(int i = 0;i <= 999999999;i++) {
count++;
}
long end = System.currentTimeMillis();
System.out.println("未使用函数自增10 0000 0000次的时间:" + (end - start) + "ms");
count = 0;
System.out.println("==========================");
start = System.currentTimeMillis();
for(int i = 0;i <= 999999999;i++) {
method();
}
end = System.currentTimeMillis();
System.out.println("使用函数完成10 0000 0000次自增的时间:" + (end - start) + "ms");
}
private static void method() {
count++;
}
}
#include <iostream>
#include <windows.h>
using namespace std;
int count = 0;
void method();
inline void fun();
int main() {
SYSTEMTIME st = { 0 };
GetLocalTime(&st);
long start = st.wHour*60*60*1000 + st.wMinute*60*1000 + st.wSecond*1000 + st.wMilliseconds;
for(int i = 0;i <= 999999999;i++) {
count++;
}
GetLocalTime(&st);
long end = st.wHour*60*60*1000 + st.wMinute*60*1000 + st.wSecond*1000 + st.wMilliseconds;
cout<<"未使用函数自增10 0000 0000次的时间:"<<end-start<<"ms"<<endl;
count = 0;
cout<<"=============================="<<endl;
GetLocalTime(&st);
start = st.wHour*60*60*1000 + st.wMinute*60*1000 + st.wSecond*1000 + st.wMilliseconds;
for(int i = 0;i <= 999999999;i++) {
method();
}
GetLocalTime(&st);
end = st.wHour*60*60*1000 + st.wMinute*60*1000 + st.wSecond*1000 + st.wMilliseconds;
cout<<"使用函数完成10 0000 0000次自增的时间:"<<end-start<<"ms"<<endl;
count = 0;
cout<<"=============================="<<endl;
GetLocalTime(&st);
start = st.wHour*60*60*1000 + st.wMinute*60*1000 + st.wSecond*1000 + st.wMilliseconds;
for(int i = 0;i <= 999999999;i++) {
fun();
}
GetLocalTime(&st);
end = st.wHour*60*60*1000 + st.wMinute*60*1000 + st.wSecond*1000 + st.wMilliseconds;
cout<<"使用内联函数完成10 0000 0000次自增的时间:"<<end-start<<"ms"<<endl;
return 0;
}
void method() {
count++;
}
inline void fun() {
count++;
}
import time
count = 0
t = time.time()
start = int(round(t * 1000))
for i in range(99999999):
count += 1
t = time.time()
end = int(round(t * 1000))
print("未使用函数自增1 0000 0000次的时间:",end-start,"ms")
count = 0
print("===============================================")
def method():
global count
count += 1
t = time.time()
start = int(round(t * 1000))
for i in range(99999999):
method()
t = time.time()
end = int(round(t * 1000))
print("使用函数完成1 0000 0000次自增的时间:",end-start,"ms")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var count = 0;
let start = new Date().getTime();
for(var i = 0;i <= 999999999;i++) {
count++;
}
let end = new Date().getTime();
console.log("未使用函数自增10 0000 0000次的时间:" + (end -start) + "ms");
count = 0;
console.log("================================================")
start = new Date().getTime();
for(var i = 0;i <= 999999999;i++) {
method();
}
end = new Date().getTime();
console.log("使用函数完成10 0000 0000次自增的时间:" + (end -start) + "ms");
function method() {
count++;
}
</script>
</body>
</html>
var count = 0;
var start = new Date().getTime();
for(var i = 0;i <= 999999999;i++) {
count++;
}
var end = new Date().getTime();
print("未使用函数自增10 0000 0000次的时间:" + (end -start) + "ms");
count = 0;
print("================================================")
start = new Date().getTime();
for(var i = 0;i <= 999999999;i++) {
method();
}
end = new Date().getTime();
print("使用函数完成10 0000 0000次自增的时间:" + (end -start) + "ms");
function method() {
count++;
}
实验:结合多种编程语言,验证频繁调用函数是否会造成系统性能损失
原文:https://www.cnblogs.com/xgp123/p/12284965.html