Skip to content

Instantly share code, notes, and snippets.

@rebolek
Last active September 18, 2019 12:01
Show Gist options
  • Save rebolek/d72f86145bcdfcb70459695ca904e23c to your computer and use it in GitHub Desktop.
Save rebolek/d72f86145bcdfcb70459695ca904e23c to your computer and use it in GitHub Desktop.
Red[]
#include %profile.red
#include %make-csv.red
right-now: func [][now/time/precise]
test-files: function [
][
files: read %.
foreach file files [
if equal? suffix? file %.csv [
test-csv file
]
]
]
test-all: function [
][
results: copy []
base: 7
pow: 3
repeat width pow [
repeat length pow [
repeat size pow [
w: base ** width
l: base ** length
s: base ** size
print ["Block of" l "records, each with" w "values, each of" s "bytes."]
block: make-block reduce [as-pair w l s]
append/only results reduce [as-pair w l s]
append/only results probe profile/count [
[csv: to-csv block]
[loaded: load-csv csv]
] 3
print ""
]
]
]
results
]
test-big: function [
"Test for 500x500/100"
][
recycle/off
probe profile/count [
[block: make-block [500x500 100]]
[csv: to-csv block]
[loaded: load-csv csv]
] 3
]
test-csv: function [
filename [file!]
][
print ["Reading file" filename]
time: right-now
file: read filename
print ["Took:" right-now - time]
print ["Converting" length? file "bytes of CSV to Red"]
time: right-now
block: load-csv file
print ["Took:" right-now - time]
print ["Converting" length? block "records of" length? block/1 "values to CSV"]
time: right-now
csv: to-csv block
print ["Took:" right-now - time]
probe equal? csv file
print ""
]
test-storage: func [
"Test different storage methods"
][
wide-csv: to-csv make-block [1000x50 100]
tall-csv: to-csv make-block [50x1000 100]
huge-csv: to-csv make-block [500x500 100]
recycle/off ; NOTE: Because of Red GC bug
foreach block [wide-csv tall-csv huge-csv][
probe block
block: get block
probe profile/count [
[data-b: load-csv block]
[to-csv data-b]
[recycle]
[data-f: load-csv/flat block]
[to-csv/skip data-f length? data-b/1]
[recycle]
[data-c: load-csv/as-columns block]
[to-csv data-c]
[recycle]
[data-r: load-csv/as-records block]
[to-csv data-r]
[recycle]
] 3
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment