Skip to content

Commit 8f3fc42

Browse files
authored
Merge pull request #17 from ora-io/dev
Dev
2 parents 7540f4d + e556f61 commit 8f3fc42

File tree

12 files changed

+1418
-783
lines changed

12 files changed

+1418
-783
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
assets/*
2+
benchmarks/*

benchmarks/consumption.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* eslint-disable @typescript-eslint/no-use-before-define */
2+
/* eslint-disable no-console */
3+
const os = require('os')
4+
5+
function getMemoryUsage() {
6+
const memoryUsage = process.memoryUsage()
7+
return {
8+
rss: memoryUsage.rss,
9+
heapTotal: memoryUsage.heapTotal,
10+
heapUsed: memoryUsage.heapUsed,
11+
external: memoryUsage.external,
12+
}
13+
}
14+
15+
function getCPUUsage() {
16+
const cpus = os.cpus()
17+
const cpuUsage = cpus.map((cpu) => {
18+
const total = Object.values(cpu.times).reduce((acc, tv) => acc + tv, 0)
19+
return {
20+
user: 100 * cpu.times.user / total,
21+
nice: 100 * cpu.times.nice / total,
22+
sys: 100 * cpu.times.sys / total,
23+
idle: 100 * cpu.times.idle / total,
24+
irq: 100 * cpu.times.irq / total,
25+
}
26+
})
27+
return cpuUsage
28+
}
29+
30+
function startUsageSchedule(mode = '') {
31+
let tenMinutes = 5 * 60 * 1000
32+
const interval = 1000
33+
const usageMemoryList = []
34+
const usageCPUList = []
35+
setInterval(() => {
36+
if (tenMinutes <= 0) {
37+
console.log(`[${mode}] Memory Average:`, computedMemoryAverage(usageMemoryList))
38+
console.log(`[${mode}] CPU Average:`, computedCPUAverage(usageCPUList))
39+
process.exit()
40+
}
41+
const memoryUsage = getMemoryUsage()
42+
usageMemoryList.push(memoryUsage)
43+
const cpuUsage = getCPUUsage()
44+
usageCPUList.push(cpuUsage)
45+
46+
console.log(`[${mode}] Memory Usage:`, `${memoryUsage.heapUsed / 1024 / 1024} MB`)
47+
// console.log(`[${mode}] CPU Usage:`, `${cpuUsage.map((v, index) => `CPU ${index + 1}: ${v.user}`).join('% \n')}%`)
48+
tenMinutes -= interval
49+
}, interval)
50+
51+
const computedMemoryAverage = (list) => {
52+
const data = list.reduce((acc, val) => {
53+
return {
54+
rss: acc.rss + val.rss,
55+
heapTotal: acc.heapTotal + val.heapTotal,
56+
heapUsed: acc.heapUsed + val.heapUsed,
57+
external: acc.external + val.external,
58+
}
59+
}, { rss: 0, heapTotal: 0, heapUsed: 0, external: 0 })
60+
return {
61+
rss: data.rss / list.length,
62+
heapTotal: data.heapTotal / list.length,
63+
heapUsed: data.heapUsed / list.length,
64+
external: data.external / list.length,
65+
}
66+
}
67+
68+
const computedCPUAverage = (list) => {
69+
const data = list.reduce((acc, val) => {
70+
return val.map((v, i) => {
71+
return {
72+
user: acc[i].user + v.user,
73+
nice: acc[i].nice + v.nice,
74+
sys: acc[i].sys + v.sys,
75+
idle: acc[i].idle + v.idle,
76+
irq: acc[i].irq + v.irq,
77+
}
78+
})
79+
}, list[0])
80+
return data.map((v) => {
81+
return {
82+
user: v.user / list.length,
83+
nice: v.nice / list.length,
84+
sys: v.sys / list.length,
85+
idle: v.idle / list.length,
86+
irq: v.irq / list.length,
87+
}
88+
})
89+
}
90+
}
91+
92+
module.exports = {
93+
startUsageSchedule,
94+
}

benchmarks/erc20.abi.json

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
[
2+
{
3+
"constant": true,
4+
"inputs": [],
5+
"name": "name",
6+
"outputs": [
7+
{
8+
"name": "",
9+
"type": "string"
10+
}
11+
],
12+
"payable": false,
13+
"stateMutability": "view",
14+
"type": "function"
15+
},
16+
{
17+
"constant": false,
18+
"inputs": [
19+
{
20+
"name": "_spender",
21+
"type": "address"
22+
},
23+
{
24+
"name": "_value",
25+
"type": "uint256"
26+
}
27+
],
28+
"name": "approve",
29+
"outputs": [
30+
{
31+
"name": "",
32+
"type": "bool"
33+
}
34+
],
35+
"payable": false,
36+
"stateMutability": "nonpayable",
37+
"type": "function"
38+
},
39+
{
40+
"constant": true,
41+
"inputs": [],
42+
"name": "totalSupply",
43+
"outputs": [
44+
{
45+
"name": "",
46+
"type": "uint256"
47+
}
48+
],
49+
"payable": false,
50+
"stateMutability": "view",
51+
"type": "function"
52+
},
53+
{
54+
"constant": false,
55+
"inputs": [
56+
{
57+
"name": "_from",
58+
"type": "address"
59+
},
60+
{
61+
"name": "_to",
62+
"type": "address"
63+
},
64+
{
65+
"name": "_value",
66+
"type": "uint256"
67+
}
68+
],
69+
"name": "transferFrom",
70+
"outputs": [
71+
{
72+
"name": "",
73+
"type": "bool"
74+
}
75+
],
76+
"payable": false,
77+
"stateMutability": "nonpayable",
78+
"type": "function"
79+
},
80+
{
81+
"constant": true,
82+
"inputs": [],
83+
"name": "decimals",
84+
"outputs": [
85+
{
86+
"name": "",
87+
"type": "uint8"
88+
}
89+
],
90+
"payable": false,
91+
"stateMutability": "view",
92+
"type": "function"
93+
},
94+
{
95+
"constant": true,
96+
"inputs": [
97+
{
98+
"name": "_owner",
99+
"type": "address"
100+
}
101+
],
102+
"name": "balanceOf",
103+
"outputs": [
104+
{
105+
"name": "balance",
106+
"type": "uint256"
107+
}
108+
],
109+
"payable": false,
110+
"stateMutability": "view",
111+
"type": "function"
112+
},
113+
{
114+
"constant": true,
115+
"inputs": [],
116+
"name": "symbol",
117+
"outputs": [
118+
{
119+
"name": "",
120+
"type": "string"
121+
}
122+
],
123+
"payable": false,
124+
"stateMutability": "view",
125+
"type": "function"
126+
},
127+
{
128+
"constant": false,
129+
"inputs": [
130+
{
131+
"name": "_to",
132+
"type": "address"
133+
},
134+
{
135+
"name": "_value",
136+
"type": "uint256"
137+
}
138+
],
139+
"name": "transfer",
140+
"outputs": [
141+
{
142+
"name": "",
143+
"type": "bool"
144+
}
145+
],
146+
"payable": false,
147+
"stateMutability": "nonpayable",
148+
"type": "function"
149+
},
150+
{
151+
"constant": true,
152+
"inputs": [
153+
{
154+
"name": "_owner",
155+
"type": "address"
156+
},
157+
{
158+
"name": "_spender",
159+
"type": "address"
160+
}
161+
],
162+
"name": "allowance",
163+
"outputs": [
164+
{
165+
"name": "",
166+
"type": "uint256"
167+
}
168+
],
169+
"payable": false,
170+
"stateMutability": "view",
171+
"type": "function"
172+
},
173+
{
174+
"payable": true,
175+
"stateMutability": "payable",
176+
"type": "fallback"
177+
},
178+
{
179+
"anonymous": false,
180+
"inputs": [
181+
{
182+
"indexed": true,
183+
"name": "owner",
184+
"type": "address"
185+
},
186+
{
187+
"indexed": true,
188+
"name": "spender",
189+
"type": "address"
190+
},
191+
{
192+
"indexed": false,
193+
"name": "value",
194+
"type": "uint256"
195+
}
196+
],
197+
"name": "Approval",
198+
"type": "event"
199+
},
200+
{
201+
"anonymous": false,
202+
"inputs": [
203+
{
204+
"indexed": true,
205+
"name": "from",
206+
"type": "address"
207+
},
208+
{
209+
"indexed": true,
210+
"name": "to",
211+
"type": "address"
212+
},
213+
{
214+
"indexed": false,
215+
"name": "value",
216+
"type": "uint256"
217+
}
218+
],
219+
"name": "Transfer",
220+
"type": "event"
221+
}
222+
]

0 commit comments

Comments
 (0)