Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns com.wsscode.pathom-benchmarks
(:require [com.wsscode.pathom.core :as p]
[com.wsscode.pathom.connect :as pc]
[com.wsscode.pathom3.connect.operation :as pco]
[com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.interface.eql :as p.eql]
[com.wsscode.pathom3.entity-tree :as p.ent]))
;; pathom 2
(pc/defresolver full-name2 [_ {::keys [first-name last-name]}]
{::pc/input #{::first-name ::last-name}
::pc/output [::full-name]}
{::full-name (str first-name " " last-name)})
(def registry2
[full-name2])
(def parser
(p/parser
{::p/env {::p/reader [p/map-reader
pc/reader2
pc/open-ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}}
::p/mutate pc/mutate
::p/plugins [(pc/connect-plugin {::pc/register registry2})
p/error-handler-plugin
p/trace-plugin]}))
(def parser-async
(p/async-parser
{::p/env {::p/reader [p/map-reader
pc/async-reader2
pc/open-ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}}
::p/mutate pc/mutate
::p/plugins [(pc/connect-plugin {::pc/register registry2})
p/error-handler-plugin
p/trace-plugin]}))
(def parser-parallel
(p/parallel-parser
{::p/env {::p/reader [p/map-reader
pc/parallel-reader
pc/open-ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}}
::p/mutate pc/mutate
::p/plugins [(pc/connect-plugin {::pc/register registry2})
p/error-handler-plugin
p/trace-plugin]}))
;; pathom 3
(pco/defresolver full-name3 [{::keys [first-name last-name]}]
::full-name (str first-name " " last-name))
(def registry3
[full-name3])
(def index3 (pci/register registry3))
(defonce plan-cache* (atom {}))
(def env3 (assoc index3 :com.wsscode.pathom3.connect.planner/plan-cache* plan-cache*))
(comment
; pathom 2 serial
(time
(dotimes [_ 1000]
(parser {::p/entity (atom {::first-name "Wilker" ::last-name "Lucio"})} [::full-name])))
; pathom 2 async
(time
(dotimes [_ 1000]
(clojure.core.async/<!! (parser-async {::p/entity (atom {::first-name "Wilker" ::last-name "Lucio"})} [::full-name]))))
; pathom 2 parallel
(time
(dotimes [_ 1000]
(clojure.core.async/<!! (parser-parallel {::p/entity (atom {::first-name "Wilker" ::last-name "Lucio"})} [::full-name]))))
; pathom 3 without plan cache
(time
(dotimes [_ 1000]
(p.eql/process (p.ent/with-entity index3
{::first-name "Wilker" ::last-name "Lucio"})
[::full-name])))
; pathom 3 with cached plan
(time
(dotimes [_ 1000]
(p.eql/process (p.ent/with-entity env3
{::first-name "Wilker" ::last-name "Lucio"})
[::full-name]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment