Skip to content

Instantly share code, notes, and snippets.

View caesaneer's full-sized avatar

Dan Casler caesaneer

View GitHub Profile
@caesaneer
caesaneer / bench.go
Created August 18, 2019 22:10
Golang - Single and 16 CPU Threads - Bench Package
package bench
import (
"math"
"strconv"
)
// CPU does stuff
func CPU(times int) []string {
// Keeps it to a 32 bit int
@caesaneer
caesaneer / main.go
Created August 18, 2019 22:10
Golang - Single and 16 CPU Threads
package main
import (
"benchmarks/pkg/bench"
"fmt"
"net/http"
"runtime"
)
func helloServer(w http.ResponseWriter, r *http.Request) {
@caesaneer
caesaneer / index.js
Created August 18, 2019 21:16
Node.js - Single Process
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)
@caesaneer
caesaneer / cpu.go
Created August 17, 2019 22:37
CPU Intensive Work
package cpu
// CPU does stuff
func CPU(times int) []int {
// Keeps it to a 32 bit int
num := 40
var r []int
for i := 0; i < times; i++ {
d := bubble(expand(reversePrime(fib(num))))
r = append(r, d[len(d)-1])
@caesaneer
caesaneer / part2.js
Created August 17, 2019 20:39
Part 2
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
// const crypto = require('crypto')
// ════════════════════════════════════════════════════════════════════════════════════════════════╡
module.exports = function CPU(times) {
// Keeps it to a 32 bit int
const num = 40
@caesaneer
caesaneer / fib.kt
Created August 16, 2019 04:44
Fibonacci
package ktor.benchmark
/* ktlint-disable no-wildcard-imports */
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.locations.*
/* ktlint-enable no-wildcard-imports */
@caesaneer
caesaneer / gen.go
Last active August 16, 2019 06:12
// Handler that calls generate
func ok(w http.ResponseWriter, r *http.Request) {
// res := make([]int64, 0, 100000)
var res [100000]int64
fibonacci.Generate(&res)
// fmt.Println(suc)
// fmt.Printf("%T", res)
// fmt.Println(res[50])
fmt.Fprintf(w, "OK")
@caesaneer
caesaneer / fib.go
Created August 14, 2019 22:40
Loop with Fibonacci Sequence
func fibonacci() []int {
var result []int
var start = 1000
for {
var num = 1250
var n1, n2, temp int = 0, 1, 0
for {
temp = n2
n2 = n1 + n2
@caesaneer
caesaneer / gist:417cd88062d3bebcfaf8708ebc17862e
Last active September 21, 2023 20:47
Go Goroutines vs Node.js Cluster & Worker Threads - Part 1 - Node.js Code - CLUSTER
const cluster = require('cluster')
const http = require('http')
const numCPUs = require('os').cpus().length
const host = '192.168.0.14'
const port = 3000
const start = async function startServer() {
// Cluster
if (cluster.isMaster) {
@caesaneer
caesaneer / index.js
Last active April 16, 2020 09:25
Go Goroutines vs Node.js Cluster & Worker Threads - Part 1 - Node.js Code - NO CLUSTER
const http = require('http')
const host = '192.168.0.14'
const port = 3000
const start = function startServer() {
// Simple request router
const router = function requestRouter(request, reply) {
reply.end('OK')
}