Skip to content

Instantly share code, notes, and snippets.

@chase-lambert
Created August 21, 2024 01:41
Show Gist options
  • Save chase-lambert/41f7e48f96ab4e8dd6551cc9c9c6166a to your computer and use it in GitHub Desktop.
Save chase-lambert/41f7e48f96ab4e8dd6551cc9c9c6166a to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 24.08.19
(ns execution-times
"assumes each task/function is only run once
and logs are clean so that the start and end
times of each task show up consecutively in
their respective order."
(:require [clojure.test :refer [deftest is]]))
(defn calculate-execution-times [logs]
(reduce (fn [acc [task1 task2]]
(let [task (:name task1)
start (:time task1)
end (:time task2)
total (- end start)]
(assoc acc task total)))
{}
(partition 2 2 (sort-by :name logs))))
(deftest calculate-execution-times-test
(let [logs [{:name "main" :time 0 :event "start"}
{:name "subTask1" :time 5 :event "start"}
{:name "subTask1" :time 10 :event "end"}
{:name "subTask2" :time 15 :event "start"}
{:name "subTask2" :time 20 :event "end"}
{:name "main" :time 25 :event "end"}]]
(is (= { "main" 25, "subTask1" 5, "subTask2" 5}
(calculate-execution-times logs)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment