-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add quicksort benchmark of float elem (#108)
Signed-off-by: zhenweijin <[email protected]>
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* This file is generated by tsc */ | ||
"use strict"; | ||
/* This file is modified base on: | ||
* https://browserbench.org/JetStream/wasm/quicksort.c | ||
*/ | ||
var SORTELEMENTS = 1e5; | ||
var seed = 0; | ||
var maximum, minimum; | ||
var sortList = new Array(SORTELEMENTS + 1); | ||
function rand() { | ||
seed = (seed * 1309 + 13849) & 65535; | ||
return seed; | ||
} | ||
function initArr() { | ||
seed = 74755; | ||
maximum = 0; | ||
minimum = 65536; | ||
for (var i = 1; i <= SORTELEMENTS; i++) { | ||
const val = rand(); | ||
sortList[i] = val + val / 65536; | ||
if (sortList[i] > maximum) { | ||
maximum = sortList[i]; | ||
} | ||
else if (sortList[i] < minimum) { | ||
minimum = sortList[i]; | ||
} | ||
} | ||
} | ||
function quickSort(a, l, r) { | ||
var i = l, j = r; | ||
var w; | ||
var idx = Math.floor((l + r) / 2); | ||
var x = a[idx]; | ||
do { | ||
while (a[i] < x) | ||
i++; | ||
while (x < a[j]) | ||
j--; | ||
if (i <= j) { | ||
w = a[i]; | ||
a[i] = a[j]; | ||
a[j] = w; | ||
i++; | ||
j--; | ||
} | ||
} while (i <= j); | ||
if (l < j) | ||
quickSort(a, l, j); | ||
if (i < r) | ||
quickSort(a, i, r); | ||
} | ||
function main() { | ||
initArr(); | ||
quickSort(sortList, 1, SORTELEMENTS); | ||
if (sortList[1] != minimum || sortList[SORTELEMENTS] != maximum) { | ||
console.log('Validate result error in quicksort'); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* This file is modified base on: | ||
* https://browserbench.org/JetStream/wasm/quicksort.c | ||
*/ | ||
const SORTELEMENTS = 1e5; | ||
let seed = 0; | ||
let maximum: number, minimum: number; | ||
const sortList = new Array<number>(SORTELEMENTS + 1); | ||
|
||
function rand() { | ||
seed = (seed * 1309 + 13849) & 65535; | ||
return seed; | ||
} | ||
|
||
function initArr() { | ||
seed = 74755; | ||
maximum = 0; | ||
minimum = 65536; | ||
|
||
for (let i = 1; i <= SORTELEMENTS; i++) { | ||
const val = rand(); | ||
sortList[i] = val + val / 65536; | ||
if (sortList[i] > maximum) { | ||
maximum = sortList[i]; | ||
} else if (sortList[i] < minimum) { | ||
minimum = sortList[i]; | ||
} | ||
} | ||
} | ||
|
||
function quickSort(a: number[], l: number, r: number) { | ||
let i = l, | ||
j = r; | ||
let w: number; | ||
const idx = Math.floor((l + r) / 2); | ||
const x = a[idx]; | ||
do { | ||
while (a[i] < x) i++; | ||
while (x < a[j]) j--; | ||
if (i <= j) { | ||
w = a[i]; | ||
a[i] = a[j]; | ||
a[j] = w; | ||
i++; | ||
j--; | ||
} | ||
} while (i <= j); | ||
|
||
if (l < j) quickSort(a, l, j); | ||
if (i < r) quickSort(a, i, r); | ||
} | ||
|
||
export function main() { | ||
initArr(); | ||
quickSort(sortList, 1, SORTELEMENTS); | ||
if (sortList[1] != minimum || sortList[SORTELEMENTS] != maximum) { | ||
console.log('Validate result error in quicksort'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters