· 4 years ago · Oct 06, 2021, 11:40 AM
1--------------------------------------------------
2-- CPU Benchmarking Functions
3--------------------------------------------------
4function GetSystemTimeSeconds()
5 local socket = require "socket"
6 return socket.gettime()*1000
7end
8function CPUBenchmark()
9 --This function gives the CPU some busy work to do.
10 --CPU score is determined by how quickly the work is completed.
11 print("test")
12 local totalTime = 0
13 local lastTime
14 local currTime
15 local countTime = 0
16 --Make everything a local variable
17 --This is necessary because we don't want LUA searching through the globals as part of the benchmark
18 local TableInsert = table.insert
19 local TableRemove = table.remove
20 local h
21 local i
22 local j
23 local k
24 local l
25 local m
26 local n = {}
27 for h = 1, 24, 1 do
28 -- If the need for the benchmark no longer exists, abort it now.
29-- if not lobbyComm then
30-- return
31-- end
32
33 lastTime = GetSystemTimeSeconds()
34-- print(lastTime)
35 for i = 1.0, 30.4, 0.0008 do
36 --This instruction set should cover most LUA operators
37 j = i + i --Addition
38 k = i * i --Multiplication
39 l = k / j --Division
40 m = j - i --Subtraction
41 j = i ^ 4 --Power
42 l = -i --Negation
43 m = {'1234567890', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', true} --Create Table
44 TableInsert(m, '1234567890') --Insert Table Value
45 k = i < j --Less Than
46 k = i == j --Equality
47 k = i <= j --Less Than or Equal to
48 k = not k
49 n[tostring(i)] = m
50 end
51 currTime = GetSystemTimeSeconds()
52 totalTime = totalTime + currTime - lastTime
53
54 if totalTime > countTime then
55 --This is necessary in order to make this 'thread' yield so other things can be done.
56 countTime = totalTime + .125
57-- coroutine.yield(1)
58 end
59 end
60 BenchTime = math.ceil(totalTime )
61 print(BenchTime)
62 return BenchTime
63
64end
65print(CPUBenchmark())
66