mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-09 08:53:10 +00:00
[wip] leo_encode, leo_decode, etc. are succeeding at basic level
need to gen random data and do random deletions similar to what's done in the c++ benchmark program being roughly ported in tests/dagger/testleopard.nim
This commit is contained in:
parent
4934d1f997
commit
8836fa8348
@ -12,21 +12,22 @@ type
|
||||
const
|
||||
header = "leopard.h"
|
||||
|
||||
{.pragma: leo, cdecl, header: header, importCpp.}
|
||||
{.pragma: leo, cdecl, header: header.}
|
||||
|
||||
proc leo_init*(): cint {.leo.}
|
||||
proc leo_init*(): cint {.leo, importCpp.}
|
||||
|
||||
func leo_result_string*(res: LeopardResult): cstring {.leo.}
|
||||
func leo_result_string*(res: LeopardResult): cstring {.leo, importc.}
|
||||
|
||||
func leo_encode_work_count*(original_count, recovery_count: cuint): cuint
|
||||
{.leo.}
|
||||
{.leo, importc.}
|
||||
|
||||
proc leo_encode*(buffer_bytes: uint64, original_count, recovery_count,
|
||||
work_count: cuint, original_data, work_data: pointer): LeopardResult {.leo.}
|
||||
work_count: cuint, original_data, work_data: pointer): LeopardResult
|
||||
{.leo, importc.}
|
||||
|
||||
func leo_decode_work_count*(original_count, recovery_count: cuint): cuint
|
||||
{.leo.}
|
||||
{.leo, importc.}
|
||||
|
||||
proc leo_decode*(buffer_bytes: uint64, original_count, recovery_count,
|
||||
work_count: cuint, original_data, recovery_data, work_data: pointer):
|
||||
LeopardResult {.leo.}
|
||||
LeopardResult {.leo, importc.}
|
||||
|
||||
@ -1,6 +1,97 @@
|
||||
# import std/os
|
||||
# import std/random
|
||||
import std/sequtils
|
||||
import std/strformat
|
||||
|
||||
import pkg/dagger/leopard
|
||||
|
||||
let lin = leo_init()
|
||||
type
|
||||
TestParameters = object
|
||||
original_count: cuint
|
||||
recovery_count: cuint
|
||||
buffer_bytes : cuint
|
||||
loss_count : cuint
|
||||
seed : cuint
|
||||
|
||||
echo ""
|
||||
echo "leo_init() return code: " & $lin
|
||||
proc init(
|
||||
T: type TestParameters,
|
||||
original_count: cuint = 100,
|
||||
recovery_count: cuint = 10,
|
||||
buffer_bytes : cuint = 64000,
|
||||
loss_count : cuint = 32768,
|
||||
seed : cuint = 2): T =
|
||||
T(original_count: original_count,
|
||||
recovery_count: recovery_count,
|
||||
buffer_bytes : buffer_bytes,
|
||||
loss_count : loss_count,
|
||||
seed : seed)
|
||||
|
||||
proc benchmark(params: TestParameters) =
|
||||
var
|
||||
original_data = newSeqWith(params.original_count.int,
|
||||
newSeq[byte](params.buffer_bytes))
|
||||
|
||||
let
|
||||
encode_work_count = leo_encode_work_count(params.original_count,
|
||||
params.recovery_count)
|
||||
decode_work_count = leo_decode_work_count(params.original_count,
|
||||
params.recovery_count)
|
||||
|
||||
debugEcho "encode_work_count: " & $encode_work_count
|
||||
debugEcho "decode_work_count: " & $decode_work_count
|
||||
|
||||
let
|
||||
total_bytes = (params.buffer_bytes * params.original_count).uint64
|
||||
|
||||
debugEcho "total_bytes: " & $total_bytes
|
||||
|
||||
var
|
||||
encode_work_data = newSeqWith(encode_work_count.int,
|
||||
newSeq[byte](params.buffer_bytes))
|
||||
decode_work_data = newSeqWith(decode_work_count.int,
|
||||
newSeq[byte](params.buffer_bytes))
|
||||
|
||||
let
|
||||
encodeResult = leo_encode(
|
||||
params.buffer_bytes,
|
||||
params.original_count,
|
||||
params.recovery_count,
|
||||
encode_work_count,
|
||||
addr original_data[0],
|
||||
addr encode_work_data[0]
|
||||
)
|
||||
|
||||
debugEcho "encodeResult: " & $leo_result_string(encodeResult)
|
||||
|
||||
let
|
||||
decodeResult = leo_decode(
|
||||
params.buffer_bytes,
|
||||
params.original_count,
|
||||
params.recovery_count,
|
||||
decode_work_count,
|
||||
addr original_data[0],
|
||||
addr encode_work_data[0],
|
||||
addr decode_work_data[0]
|
||||
)
|
||||
|
||||
debugEcho "decodeResult: " & $leo_result_string(decodeResult)
|
||||
|
||||
proc main() =
|
||||
if leo_init() != 0: raise (ref Defect)(msg: "Leopard failed to initialize")
|
||||
|
||||
var params = TestParameters.init
|
||||
|
||||
debugEcho fmt(
|
||||
"Parameters: " &
|
||||
"[original count={params.original_count}] " &
|
||||
"[recovery count={params.recovery_count}] " &
|
||||
"[buffer bytes={params.buffer_bytes}] " &
|
||||
"[loss count={params.loss_count}] " &
|
||||
"[random seed={params.seed}]"
|
||||
)
|
||||
|
||||
benchmark params
|
||||
|
||||
when true: # isMainModule:
|
||||
# randomize()
|
||||
main()
|
||||
|
||||
@ -6,5 +6,4 @@ import ./dagger/testmanifest
|
||||
import ./dagger/testnode
|
||||
import ./dagger/testleopard
|
||||
|
||||
|
||||
{.warning[UnusedImport]: off.}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user