Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Casler danielcasler

View GitHub Profile
@danielcasler
danielcasler / svelte.config.js
Created Aug 5, 2021
Final svelte.config.js file
View svelte.config.js
import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
View gist:9dec992c43c8d44314ddac9ef4312522
import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
@danielcasler
danielcasler / worker.js
Created Aug 18, 2019
Part 2 - Worker Threads - Worker.js
View worker.js
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const { parentPort, workerData } = require('worker_threads')
const bench = require('./bench')
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
parentPort.on('message', () => {
const result = bench(100)
parentPort.postMessage(result)
@danielcasler
danielcasler / index.js
Created Aug 18, 2019
Part 2 - Worker Threads - Index.js
View index.js
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const http = require('http')
const { StaticPool } = require('node-worker-threads-pool')
const numCPUs = require('os').cpus().length
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const host = '192.168.0.14'
const port = 8080
@danielcasler
danielcasler / index.js
Last active Aug 18, 2019
Part 2 - Node Cluster Module
View index.js
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const cluster = require('cluster')
const http = require('http')
const numCPUs = require('os').cpus().length
const bench = require('./bench')
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
const host = '192.168.0.14'
@danielcasler
danielcasler / index.js
Created Aug 18, 2019
Part 2 - Node.js Single Process
View index.js
const http = require('http')
const bench = require('./bench')
const host = '192.168.0.14'
const port = 8000
const start = function startServer() {
// Simple request router
const router = function requestRouter(request, reply) {
const result = bench(100)
@danielcasler
danielcasler / index.js
Created Aug 18, 2019
Node Bench Module
View index.js
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
// Calculate Fibonacci sequence for num
function fib(n) {
if (n > 40) {
throw new TypeError('Fib: N is greater than 40.')
}
const s = [1]
@danielcasler
danielcasler / bench.go
Created Aug 18, 2019
Golang - Single and 16 CPU Threads - Bench Package
View bench.go
package bench
import (
"math"
"strconv"
)
// CPU does stuff
func CPU(times int) []string {
// Keeps it to a 32 bit int
@danielcasler
danielcasler / main.go
Created Aug 18, 2019
Golang - Single and 16 CPU Threads
View main.go
package main
import (
"benchmarks/pkg/bench"
"fmt"
"net/http"
"runtime"
)
func helloServer(w http.ResponseWriter, r *http.Request) {
@danielcasler
danielcasler / index.js
Created Aug 18, 2019
Node.js - Single Process
View index.js
const http = require('http')
const bench = require('./bench')
const host = '192.168.0.14'
const port = 8000
const start = function startServer() {
// Simple request router
const router = function requestRouter(request, reply) {
const result = bench(100)