-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdeinterleave-bench.html
177 lines (153 loc) · 4.85 KB
/
deinterleave-bench.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>deinterleave Optimization Benchmark Comparison</title>
<script src="https://cdn.plot.ly/plotly-2.18.1.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
}
#deinterleaveChart {
margin-top: 20px;
}
</style>
</head>
<body>
<div id="deinterleaveChart"></div>
<script>
// Deterministic setup function
function setupDeterministicDeinterleave() {
const numChannels = Math.floor(Math.random() * 5) + 2;
const input = Array.from({ length: numChannels }, () =>
Array(128).fill(0).map(() => Math.random())
);
const output = new Float32Array(numChannels * 128);
return { input, output };
}
// Baseline implementation
function deinterleaveBaseline(DATA) {
const input = DATA.input;
const output = DATA.output;
let out_idx = 0;
for (let i = 0; i < 128; i++) {
for (let channel = 0; channel < input.length; channel++) {
output[out_idx] = input[channel][i];
out_idx++;
}
}
}
// Unroll 4 implementation
function deinterleaveUnroll4(DATA) {
const unrollFactor = 4;
const input = DATA.input;
const output = DATA.output;
let out_idx = 0;
let inputLength = input.length;
for (let i = 0; i < 128; i += unrollFactor) {
for (let channel = 0; channel < inputLength; channel++) {
output[out_idx] = input[channel][i];
output[out_idx + 1] = input[channel][i + 1];
output[out_idx + 2] = input[channel][i + 2];
output[out_idx + 3] = input[channel][i + 3];
out_idx += unrollFactor;
}
}
}
// Unroll 8 implementation
function deinterleaveUnroll8(DATA) {
const unrollFactor = 8;
const input = DATA.input;
const output = DATA.output;
let out_idx = 0;
let inputLength = input.length;
for (let i = 0; i < 128; i += unrollFactor) {
for (let channel = 0; channel < inputLength; channel++) {
for (let u = 0; u < unrollFactor; u++) {
output[out_idx + u] = input[channel][i + u];
}
out_idx += unrollFactor;
}
}
}
// Unroll 16 implementation
function deinterleaveUnroll16(DATA) {
const unrollFactor = 16;
const input = DATA.input;
const output = DATA.output;
let out_idx = 0;
let inputLength = input.length;
for (let i = 0; i < 128; i += unrollFactor) {
for (let channel = 0; channel < inputLength; channel++) {
for (let u = 0; u < unrollFactor; u++) {
output[out_idx + u] = input[channel][i + u];
}
out_idx += unrollFactor;
}
}
}
const batchSize = 10000;
// pre-generating random data to not affect the benchmark
const data = Array.from({ length: batchSize }, () => setupDeterministicDeinterleave());
function runDeinterleaveBenchmark(data, technique, iterations, batchSize = 10000) {
const timings = [];
for (let i = 0; i < iterations; i++) {
const start = performance.now();
for (let j = 0; j < batchSize; j++) {
technique(data[j]);
}
const end = performance.now();
timings.push(((end - start) * 1000) / batchSize);
}
return timings;
}
const deinterleaveBaselineTimings = runDeinterleaveBenchmark(data, deinterleaveBaseline, 250, batchSize);
const deinterleaveUnroll4Timings = runDeinterleaveBenchmark(data, deinterleaveUnroll4, 250, batchSize);
const deinterleaveUnroll8Timings = runDeinterleaveBenchmark(data, deinterleaveUnroll8, 250, batchSize);
const deinterleaveUnroll16Timings = runDeinterleaveBenchmark(data, deinterleaveUnroll16, 250, batchSize);
const deinterleaveData = [
{
x: deinterleaveBaselineTimings,
type: 'histogram',
name: 'Baseline',
opacity: 0.7
},
{
x: deinterleaveUnroll4Timings,
type: 'histogram',
name: 'Unroll 4',
opacity: 0.7
},
{
x: deinterleaveUnroll8Timings,
type: 'histogram',
name: 'Unroll 8',
opacity: 0.7
},
{
x: deinterleaveUnroll16Timings,
type: 'histogram',
name: 'Unroll 16',
opacity: 0.7
}
];
const deinterleaveLayout = {
title: 'Deinterleave Performance Comparison',
xaxis: {
title: 'Time (µs)',
showgrid: true
},
yaxis: {
title: 'Frequency',
showgrid: true
},
barmode: 'overlay',
legend: { orientation: 'h', x: 0.5, xanchor: 'center', y: 1.1 }
};
Plotly.newPlot('deinterleaveChart', deinterleaveData, deinterleaveLayout);
</script>
</body>
</html>