Created
December 16, 2013 14:17
-
-
Save jebberjeb/7987593 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns test-app.foo | |
(:require [taoensso.timbre.profiling :as p] | |
[datomic.api :as d])) | |
;; GOALS | |
;; * perf test both approaches | |
;; * compare size/complexity of code for boath approaches | |
;; Properties from input file. Only properties w/ even :id have been selected. | |
(def props-from-file | |
(for [x (filter even? (range 100))] | |
{:id x :name (str "Property " x)})) | |
;; Groups of properties representing get-properties for each of N OAuth users. | |
(def props-from-api | |
(->> (range 25) | |
(map #(hash-map :id % :email (str "foo" % "@bar.com"))) | |
(partition 5))) | |
;;**************************************************************************** | |
;; Technique 1 - for each OAuth user, filter their properties by selected, then | |
;; map/assoc email address to each. | |
;; Invariants | |
(def m-sel-props (->> props-from-file | |
(map (juxt :id identity)) | |
(into {}))) | |
(defn t1 [] | |
(->> props-from-api | |
(flatten) | |
(filter (fn [p] (some #{(:id p)} (map :id props-from-file)))) | |
(map (fn [p] (assoc p :name (->> p :id (get m-sel-props) :name)))))) | |
;;**************************************************************************** | |
;; Technique 2 - use datomic to try and join it all in one shot. | |
;; Invariants | |
(def p-api (map (juxt :id :email) (flatten props-from-api))) | |
(def p-fil (map (juxt :id :name) props-from-file)) | |
(defn t2 [] | |
(d/q '[:find ?id ?name ?email | |
:in $a $b | |
:where [$a ?id ?email] | |
[$b ?id ?name]] | |
p-api | |
p-fil)) | |
;;**************************************************************************** | |
;; Convert both to set of sets for comparison. | |
(assert (= (set (map set (t2))) | |
(set (map (comp set vals) (t1))))) | |
(defn doit | |
[] | |
(p/p :func (doall (t1))) | |
(p/p :dato (doall (t2)))) | |
(p/profile :info :Joins (dotimes [n 1000] (doit))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment