Skip to content

Commit

Permalink
benchmark: fixed random value generation error
Browse files Browse the repository at this point in the history
Signed-off-by: zhenweijin <[email protected]>
  • Loading branch information
kylo5aby committed Jun 6, 2024
1 parent 228cb80 commit 841a9b8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
8 changes: 5 additions & 3 deletions tests/benchmark/quicksort.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
var SORTELEMENTS = 1e5;
var maximum = 0;
var minimum = 65536;
function rand(seed) {
var seed = 74755;

function rand() {
seed = (seed * 1309 + 13849) & 65535;
return seed;
}

function initArr(sortList) {
var seed = 74755;
for (var i = 1; i <= SORTELEMENTS; i++) {
sortList[i] = rand(seed);
sortList[i] = rand();
if (sortList[i] > maximum) {
maximum = sortList[i];
}
Expand Down
7 changes: 3 additions & 4 deletions tests/benchmark/quicksort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
const SORTELEMENTS = 1e5;
let maximum = 0;
let minimum = 65536;
let seed = 74755;

function rand(seed: number) {
function rand() {
seed = (seed * 1309 + 13849) & 65535;
return seed;
}

function initArr(sortList: number[]) {
const seed = 74755;

for (let i = 1; i <= SORTELEMENTS; i++) {
sortList[i] = rand(seed);
sortList[i] = rand();
if (sortList[i] > maximum) {
maximum = sortList[i];
} else if (sortList[i] < minimum) {
Expand Down
7 changes: 4 additions & 3 deletions tests/benchmark/quicksort_float.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
var SORTELEMENTS = 1e5;
var maximum = 0;
var minimum = 65536;
function rand(seed) {
var seed = 74755;

function rand() {
seed = (seed * 1309 + 13849) & 65535;
return seed;
}
function initArr(sortList) {
var seed = 74755;
for (var i = 1; i <= SORTELEMENTS; i++) {
var val = rand(seed);
var val = rand();
sortList[i] = val + val / 65536;
if (sortList[i] > maximum) {
maximum = sortList[i];
Expand Down
5 changes: 3 additions & 2 deletions tests/benchmark/quicksort_float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
const SORTELEMENTS = 1e5;
let maximum = 0;
let minimum = 65536;
let seed = 74755;

function rand(seed: number) {
function rand() {
seed = (seed * 1309 + 13849) & 65535;
return seed;
}
Expand All @@ -14,7 +15,7 @@ function initArr(sortList: number[]) {
const seed = 74755;

for (let i = 1; i <= SORTELEMENTS; i++) {
const val = rand(seed);
const val = rand();
sortList[i] = val + val / 65536;
if (sortList[i] > maximum) {
maximum = sortList[i];
Expand Down

0 comments on commit 841a9b8

Please sign in to comment.