angch.venice.1.12.34.source-code.jsonl-bulk-demo.venice Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of venice Show documentation
Show all versions of venice Show documentation
Venice, a sandboxed Lisp implemented in Java.
The newest version!
;;;; __ __ _
;;;; \ \ / /__ _ __ (_) ___ ___
;;;; \ \/ / _ \ '_ \| |/ __/ _ \
;;;; \ / __/ | | | | (_| __/
;;;; \/ \___|_| |_|_|\___\___|
;;;;
;;;;
;;;; Copyright 2017-2024 Venice
;;;;
;;;; Licensed under the Apache License, Version 2.0 (the "License");
;;;; you may not use this file except in compliance with the License.
;;;; You may obtain a copy of the License at
;;;;
;;;; http://www.apache.org/licenses/LICENSE-2.0
;;;;
;;;; Unless required by applicable law or agreed to in writing, software
;;;; distributed under the License is distributed on an "AS IS" BASIS,
;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;;; See the License for the specific language governing permissions and
;;;; limitations under the License.
(do
(load-module :jsonl)
(load-module :timing ['timing :as 't])
(defn create-data [lines]
(let [data {"a" 100, "b" 200}]
(reduce #(conj %1 (assoc data :index %2)) [] (range 0 lines))))
(defn write [file data]
(try-with [wr (io/buffered-writer file)]
(jsonl/spit wr data)
(flush wr)))
(defn read [file]
(try-with [rd (io/buffered-reader file)]
(jsonl/slurp rd)))
(defn create-with-timing [lines]
(t/run #(create-data lines) "\nCreating data records..."))
(defn write-with-timing [file lines]
(let [data (create-with-timing lines)]
(t/run #(write file data) (str "\nWriting " lines " records..."))))
(defn read-with-timing [file]
(t/run #(read file) "\nReading..." #(printf "Read %d records.%n" (count %))))
(let [file (io/file "jsonl-bulk-demo.jsonl")
lines 10_000]
(write-with-timing file lines)
(read-with-timing file)
nil))