-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
946403f
commit 151f80e
Showing
3 changed files
with
71 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,18 @@ | ||
// taken mostly from hermes | ||
|
||
function bench (lc, fc) { | ||
var n, fact; | ||
var res = 0; | ||
while (--lc >= 0) { | ||
n = fc; | ||
fact = n; | ||
while (--n > 1) | ||
fact *= n; | ||
res += fact; | ||
} | ||
return res; | ||
} | ||
|
||
let t1 = performance.now(); | ||
var res = bench(4e6, 100); | ||
print(performance.now() - t1); |
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,41 @@ | ||
const start = performance.now(); | ||
|
||
// Define your two arrays of numbers | ||
const array1 = [1, 2, 3, 4, 5]; | ||
const array2 = [5, 4, 3, 2, 1]; | ||
|
||
const mean = arr => { | ||
arr ??= []; | ||
|
||
let sum = 0; | ||
for (const x of arr) { | ||
sum += x; | ||
} | ||
|
||
return sum / arr.length; | ||
}; | ||
|
||
// Calculate the mean of each array | ||
// const mean1 = array1.reduce((acc, val) => acc + val, 0) / array1.length; | ||
// const mean2 = array2.reduce((acc, val) => acc + val, 0) / array2.length; | ||
const mean1 = mean(array1); | ||
const mean2 = mean(array2); | ||
|
||
// Calculate the numerator and denominators for Pearson correlation | ||
let numerator = 0; | ||
let denominator1 = 0; | ||
let denominator2 = 0; | ||
|
||
for (let i = 0; i < array1.length; i++) { | ||
const diff1 = array1[i] - mean1; | ||
const diff2 = array2[i] - mean2; | ||
numerator += diff1 * diff2; | ||
denominator1 += diff1 * diff1; | ||
denominator2 += diff2 * diff2; | ||
} | ||
|
||
// Calculate the correlation coefficient | ||
const correlationCoefficient = numerator / Math.sqrt(denominator1 * denominator2); | ||
|
||
console.log(correlationCoefficient); | ||
console.log(performance.now() - start); |
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,12 @@ | ||
let t = performance.now(); | ||
|
||
let i = 0; | ||
while (i < 100_000) { | ||
'abc'.isWellFormed() // true | ||
'🔥'.isWellFormed() // true | ||
'\uD83D'.isWellFormed() // false | ||
|
||
i += 1; | ||
} | ||
|
||
console.log(performance.now() - t); |