Skip to content

Commit

Permalink
Diverse WIP and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomazPom committed Sep 7, 2024
1 parent c8b4f9e commit fff6c1a
Show file tree
Hide file tree
Showing 7 changed files with 1,803 additions and 485 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:


# Upload zip file to the release
- name: Upload binaries to release
- name: Upload assets to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
15 changes: 0 additions & 15 deletions UDCompress.ps1

This file was deleted.

858 changes: 389 additions & 469 deletions background.js

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions other-tools-and-tests/benchs/background_darkening.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function versionCode1(l, A, B) {
return Math.min(2 * A * l, A + 2 * (B - A) * (l - 0.5));
}

function versionCode2(l, A, B) {
if (l < 0.5) {
return 2 * A * l;
} else {
return A + 2 * (B - A) * (l - 0.5);
}
}

function versionCode3(l, A, B) {
return (l < 0.5) ? (2 * A * l) : (A + 2 * (B - A) * (l - 0.5));
}

function benchmark(func, iterations, A, B) {
const start = performance.now();
for (let i = 0; i < iterations; i++) {
const l = Math.random();
func(l, A, B);
}
const end = performance.now();
return end - start;
}

const A = 0.4;
const B = 0.1;
const iterations = 10000000;

const time1 = benchmark(versionCode1, iterations, A, B);
console.log(`Version Code 1 took ${time1.toFixed(2)} ms`);

const time2 = benchmark(versionCode2, iterations, A, B);
console.log(`Version Code 2 took ${time2.toFixed(2)} ms`);

const time3 = benchmark(versionCode3, iterations, A, B);
console.log(`Version Code 3 took ${time3.toFixed(2)} ms`);

const percentageSlowV1 = ((time1 - time2) / time2) * 100;
const percentageSlowV3 = ((time3 - time2) / time2) * 100;

console.log(`Version Code 1 is ${percentageSlowV1.toFixed(2)}% slower than Version Code 2`);
console.log(`Version Code 3 is ${percentageSlowV3.toFixed(2)}% slower than Version Code 2`);
70 changes: 70 additions & 0 deletions other-tools-and-tests/benchs/foreground_lightening.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function benchmark() {
let iterations = 1000000; // 10 million iterations
let A, B, l;

// Array of anonymous functions representing the code snippets
const codeSnippets = [
{
name: "First Code",
func: () => {
l = Math.random(); // Generate random number between 0 and 1
A = Math.random(); // Generate random A between 0 and 1
B = Math.random(); // Generate random B between 0 and 1
l = l < 0.5
? 2 * l * (A - B) + B
: 2 * l * (B - A) + (2 * A - B);
}
},
{
name: "Second Code",
func: () => {
l = Math.random(); // Generate random number between 0 and 1
A = Math.random(); // Generate random A between 0 and 1
B = Math.random(); // Generate random B between 0 and 1
l = Math.min(2 * l, -2 * l + 2) * (A - B) + B;
}
}
// You can add more code snippets here.
];

// Array to store the benchmarking times
let times = [];

// Loop through each code snippet and benchmark it
codeSnippets.forEach((snippet) => {
console.log(`${snippet.name}:`,snippet.func.toString());
console.time(snippet.name);
let start = performance.now();
for (let i = 0; i < iterations; i++) {
snippet.func(); // Execute the anonymous function
}
let end = performance.now();
let timeTaken = end - start;
console.timeEnd(snippet.name);

// Store the time taken for this snippet
times.push({
name: snippet.name,
time: timeTaken
});

console.log(`Time taken by ${snippet.name}: ${timeTaken.toFixed(2)} ms`);
});

// Sort times array based on performance (ascending order)
times.sort((a, b) => a.time - b.time);

// Display the sorted order and comparison with the fastest one
console.log("\nPerformance Comparison (Fastest to Slowest):");
const fastestTime = times[0].time; // Time of the fastest code
times.forEach((snippet, index) => {
let diff = snippet.time - fastestTime;
let percentageDiff = (diff / fastestTime) * 100;
console.log(`${index + 1}. ${snippet.name} - ${snippet.time.toFixed(2)} ms (${percentageDiff.toFixed(2)}% slower than the fastest)`);
});

// Show which one is the fastest
console.log(`\n${times[0].name} is the fastest, taking ${fastestTime.toFixed(2)} ms`);
}

benchmark();
51 changes: 51 additions & 0 deletions other-tools-and-tests/benchs/hsla_vs_rgba_val_rendering.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{

function getRandomInt(max) {
return Math.floor(Math.random() * max);
}

function benchmark(render) {
const start = performance.now();
for (let i = 0; i < 500000; i++) {
const r = getRandomInt(256); // Random value between 0 and 255
const g = getRandomInt(256);
const b = getRandomInt(256);
uDark.rgba(r, g, b, 1, render); // Call with random RGB values
}
const end = performance.now();
return end - start; // Return the time in milliseconds
}

// Running benchmarks for uDark.rgba_val
const timeRgba = benchmark(uDark.rgba_val);
console.log(`Benchmark for uDark.rgba_val: ${timeRgba.toFixed(2)}ms`);

// Running benchmarks for uDark.hsla_val
const timeHsla = benchmark(uDark.hsla_val);
console.log(`Benchmark for uDark.hsla_val: ${timeHsla.toFixed(2)}ms`);

// Ensure both times are valid and determine the faster one
if (typeof timeRgba === 'number' && typeof timeHsla === 'number') {
let faster, slower, renderFaster, renderSlower;

if (timeRgba < timeHsla) {
faster = timeRgba;
slower = timeHsla;
renderFaster = 'uDark.rgba_val';
renderSlower = 'uDark.hsla_val';
} else {
faster = timeHsla;
slower = timeRgba;
renderFaster = 'uDark.hsla_val';
renderSlower = 'uDark.rgba_val';
}

// Calculate the percentage of slowness
const percentageSlowness = ((slower - faster) / faster) * 100;

console.log(`${renderSlower} is slower by ${percentageSlowness.toFixed(2)}% compared to ${renderFaster}.`);
} else {
console.error("Timing values are not valid.");
}

}
Loading

0 comments on commit fff6c1a

Please sign in to comment.