Skip to content

Instantly share code, notes, and snippets.

Mike Anderson mikera

Block or report user

Report or block mikera

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View clj-1.8.0-alpha2-tuple-perf.clj
;; *clojure-version*
;; (require '[taoensso.encore :as encore])
(let [v [1 2 3 4]
x 1
y 2
z 3]
(encore/qbench ; Returns fastest of 3 sets of lap times for each form, in msecs
1000000 ; Number of laps
@mikera
mikera / gist:8bcbf0e037df312c6bf6
Last active Aug 29, 2015
Tuple performance testing with core.matrix
View gist:8bcbf0e037df312c6bf6
;; Using criterium to test performance of Tuples
;;
;; Benchmark using parts of the core.matrix implementation test suite
;;
;; ===========================================================
;; Common setup:
(use '[criterium.core :as c])
(require 'clojure.core.matrix.compliance-tester)
@mikera
mikera / gist:2a3ed082b07a4f65cbcc
Last active Sep 9, 2015
Exploring overhead of var indirection in Clojure
View gist:2a3ed082b07a4f65cbcc
;; =======================================================================
;; Motivation: we are interested in the performance of tiny
;; wrapper functions which look like:
;; (fn [_ x y] (g x y))
;;
;; Question: are they getting the full performance benefits of inlining?
(ns test
(:require [criterium.core :as c]))
@mikera
mikera / clojure-match.clj
Created Sep 5, 2012 — forked from ckirkendall/clojure-match.clj
Language Compare F#, Ocaml, Scala, Clojure, Ruby and Haskell - Simple AST example
View clojure-match.clj
(use '[clojure.core.match :only [match]])
(defn evaluate [env [sym x y]]
(match [sym]
['Number] x
['Add] (+ (evaluate env x) (evaluate env y))
['Multiply] (* (evaluate env x) (evaluate env y))
['Variable] (env x)))
(def environment {"a" 3, "b" 4, "c" 5})
@mikera
mikera / gist:1332788
Created Nov 2, 2011
Incanter examples
View gist:1332788
(sample-normal 5)
=> (-0.10224658005696823 -0.39374760130345093 -0.9347003327466611 0.027885002566669224 -0.5329681018922551)
(view (histogram (sample-normal 1000)))
(view (function-plot sin -10 10))
@mikera
mikera / gist:1332761
Created Nov 2, 2011
Cool Clojure examples
View gist:1332761
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Frequency analysis (implicitly treating a string as a sequence of chars)
(frequencies "abracadabra")
=> {\a 5, \b 2, \r 2, \c 1, \d 1}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Infinite, lazily calculated sequence of Fibonacci numbers
View enodyt-4clojure-solution94.clj
;; enodyt's solution to Game of Life
;; https://4clojure.com/problem/94
(fn [board]
(let [dx (count (first board))
dy (count board)
neighbours (fn [pos board]
(let [xs [[-1 -1] [0 -1] [1 -1]
[-1 0] [1 0]
[-1 1] [0 1] [1 1]]]
@mikera
mikera / gist:1104578
Created Jul 25, 2011
Clojure quick tutorial
View gist:1104578
;; Objective
;; 1. Learn Clojure by doing Clojure
;;
;; Pre-requisites
;; You need to have a running Clojure REPL
;; see: http://clojure.org/getting_started
; Hello World in Clojure
(println "Hello World")
@mikera
mikera / gist:970439
Created May 13, 2011
Options for state update in Clojure
View gist:970439
;; event application with subsequent events
;; event :: state -> (state' [event])
(defn update-with-events [state events]
(if-let [event (first events)]
(let [other-events (rest events)
[updated-state new-events] (event game)]
(recur updated-state (concat other-events new-events)))
state ))
You can’t perform that action at this time.