Skip to content

Instantly share code, notes, and snippets.

View jasonsturges's full-sized avatar

Jason Sturges jasonsturges

View GitHub Profile
@jasonsturges
jasonsturges / global.css
Created December 11, 2020 05:28
3D with Svelte and Three.js
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0
}
@jasonsturges
jasonsturges / scene.js
Created December 11, 2020 04:34
3D with Svelte and Three.js
import * as THREE from 'three';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
let renderer;
scene.add(cube);
camera.position.z = 5;
@jasonsturges
jasonsturges / App.svelte
Created December 11, 2020 04:16
3D with Svelte and Three.js
<script>
import { onMount } from 'svelte';
import { createScene } from "./scene";
let el;
onMount(() => {
createScene(el)
});
</script>
@jasonsturges
jasonsturges / main.dev.js
Last active November 30, 2020 05:10
Electron Multiple Windows
const windows = new Set();
export const createWindow = async () => {
if (
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
) {
await installExtensions();
}
@jasonsturges
jasonsturges / performanceNow.js
Created November 22, 2020 02:10
High Resolution Time Stamp
const t0 = performance.now();
Math.log10(n)
const t1 = performance.now();
console.log(`Call took ${t1 - t0} milliseconds.`);
@jasonsturges
jasonsturges / benchmark.js
Created August 26, 2020 07:20
Benchmarking JavaScript - Baseline time
const runBaseline = (iterations = 100000000) => {
let startTime = new Date().getTime();
for (let i = 0; i < iterations; i++) {
// no operation
}
let endTime = new Date().getTime();
return endTime - startTime;
}
const runTest = (iterations = 100000000) => {
@jasonsturges
jasonsturges / benchmark.js
Created August 26, 2020 06:51
Benchmarking JavaScript - Asynchronous execution
const runTest = (iterations = 100000000) => {
let startTime = new Date().getTime();
for (let i = 0; i < iterations; i++)
Math.log10(0)
let endTime = new Date().getTime();
let totalTime = endTime - startTime;
let fnTime = (totalTime / iterations).toFixed(10);
let operations = Math.floor(1000 / totalTime * iterations);
@jasonsturges
jasonsturges / benchmark.js
Created August 26, 2020 06:31
Benchmarking JavaScript - Tuning execution time
const runTest = (iterations = 100000000) => {
let startTime = new Date().getTime();
for (let i = 0; i < iterations; i++)
Math.log10(0)
let endTime = new Date().getTime();
let totalTime = endTime - startTime;
let fnTime = (totalTime / iterations).toFixed(10);
let operations = Math.floor(1000 / totalTime * iterations);
@jasonsturges
jasonsturges / benchmark.js
Created August 25, 2020 06:56
Benchmarking JavaScript - Setting up a timer
let iterations = 100000;
let startTime = new Date().getTime();
for (let i = 0; i < iterations; i++)
Math.log10(0)
let endTime = new Date().getTime();
let time = endTime - startTime;
console.info(`time: ${time}ms, op: ${time / iterations}ms`);
@jasonsturges
jasonsturges / Math.log10.js
Last active August 25, 2020 06:03
Math.log10
Math.log10(n);
// Equivalent polyfill:
Math.log(n) * Math.LOG10E