Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
juerg committed Dec 8, 2023
1 parent 06bcfc0 commit 2ca60af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
49 changes: 25 additions & 24 deletions doc/examples/scripts/aes-speed.venice
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

;;;; Compares AES-256 encryption/decryption speed

;; MacBookAir M2 2022
;; MacBookAir M2, Java 8 (Zulu)
;; --------------------------------------------------------------------
;; 2KB 20KB 200KB 2MB 20MB 200MB
;; --------------------------------------------------------------------
Expand All @@ -42,6 +42,7 @@


(defonce passwd "j87vhfrtxvzrzver445dffg")
(defonce test-dir (io/file (io/user-home-dir) "Desktop/aes-test"))


(defn identical [file1 file2]
Expand Down Expand Up @@ -79,7 +80,7 @@
(defn run [size-kb]
(let [size (* size-kb 1024)
data (bytebuf-allocate-random size)
dir (io/file (io/user-home-dir) "Desktop/aes-test")
dir test-dir
data-file (io/file dir "test.data")
aes-file-cbc-enc (io/file dir "test.data.aes-cbc.enc")
aes-file-cbc-dec (io/file dir "test.data.aes-cbc.dec")
Expand All @@ -88,48 +89,48 @@
aes-file-zip (io/file dir "test.data.zip")
aes-file-unzip (io/file dir "test.data.unzip")]
(when-not (io/exists-dir? dir)
(throw (ex :VncException (str "The dir " dir " doesnot exist!)"))))
(throw (ex :VncException (str "The dir " dir " does not exist!)"))))

(println "Testing file:" data-file (str size-kb "KB"))
(println " size:" size)

;; create the test data file (a buffer with random bytes)
(io/spit data-file data)
(io/slurp file :binary true) ;; warm up os file read
(io/slurp data-file :binary true) ;; warm up os file read
(println " : created")
(println)

(let [t (timing/elapsed (fn [] (encrypt-aes data-file
aes-file-cbc-enc
passwd)))]
(let [t (timing/elapsed #(encrypt-aes data-file
aes-file-cbc-enc
passwd))]
(printel "Encrypt AES CBC:" t))


(let [t (timing/elapsed (fn [] (decrypt-aes aes-file-cbc-enc
aes-file-cbc-dec
passwd)))]
(let [t (timing/elapsed #(decrypt-aes aes-file-cbc-enc
aes-file-cbc-dec
passwd))]
(printel "Decrypt AES CBC:" t))

(let [t (timing/elapsed (fn [] (encrypt-aes data-file
aes-file-gcm-enc
passwd)))]
(let [t (timing/elapsed #(encrypt-aes data-file
aes-file-gcm-enc
passwd))]
(printel "Encrypt AES GCM:" t))

(let [t (timing/elapsed (fn [] (decrypt-aes aes-file-gcm-enc
aes-file-gcm-dec
passwd)))]
(let [t (timing/elapsed #(decrypt-aes aes-file-gcm-enc
aes-file-gcm-dec
passwd))]
(printel "Decrypt AES GCM:" t))

(let [t (timing/elapsed (fn [] (encrypt-zip aes-file-zip
passwd
(io/file-name aes-file-unzip)
data-file)))]
(let [t (timing/elapsed #(encrypt-zip aes-file-zip
passwd
(io/file-name aes-file-unzip)
data-file))]
(printel "Encrypt AES ZIP:" t))

(let [t (timing/elapsed (fn [] (decrypt-zip aes-file-zip
passwd
(io/file-name aes-file-unzip)
(io/file-parent aes-file-unzip))))]
(let [t (timing/elapsed #(decrypt-zip aes-file-zip
passwd
(io/file-name aes-file-unzip)
(io/file-parent aes-file-unzip)))]
(printel "Decrypt AES ZIP:" t))

(println)
Expand Down
7 changes: 4 additions & 3 deletions doc/examples/scripts/hash-speed.venice
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

;;;; Compares hashing speed

;; MacBookAir M2 2022
;; MacBookAir M2, Java 8 (Zulu)
;; --------------------------------------------------------------------
;; 2KB 20KB 200KB 2MB 20MB 200MB
;; --------------------------------------------------------------------
Expand All @@ -43,6 +43,7 @@

(defonce passwd "j87vhfrtxvzrzver445dffg")
(defonce salt "12647458820938745388281")
(defonce test-dir (io/file (io/user-home-dir) "Desktop/aes-test"))


(defn identical [file1 file2]
Expand All @@ -55,11 +56,11 @@
(defn run [size-kb]
(let [size (* size-kb 1024)
data (bytebuf-allocate-random size)
dir (io/file (io/user-home-dir) "Desktop/aes-test")
dir test-dir
file (io/file dir "test.data")
algos ["MD5" "SHA-1" "SHA-256"]]
(when-not (io/exists-dir? dir)
(throw (ex :VncException (str "The dir " dir " doesnot exist!)"))))
(throw (ex :VncException (str "The dir " dir " does not exist!)"))))

(println "Testing file:" file (str size-kb "KB"))
(println " size:" size)
Expand Down

0 comments on commit 2ca60af

Please sign in to comment.