Thank you for the suggestions. I was not aware of NimYAML - I'll give it a look.
My main purpose of the question was to ensure, that my solution using _tables_
had "the best" performance. When doing a simple comparing of _tables_, _const_
and _parsecfg_ with echo, constants is the winner. But I have not yet figured
out, how to access them with concentrated strings.
import strutils, times, tables, parsecfg
# First run
# Tables
const langFile = "help_DKc=Hjælp"
var data1 = initTable[string, string]()
var dead1 = ""
for line in langFile.splitLines:
var chunks = split(line, '=')
data1[chunks[0]] = chunks[1]
let t1 = epochTime()
for i in countup(1, 1000):
#echo data1["help_DKc"]
dead1 = data1["help_DKc"]
let t1done = epochTime() - t1
# Second run
# Constants
const help_DKc = "Hjælp"
var dead2 = ""
let t2 = epochTime()
for i in countup(1, 1000):
#echo help_DKc
dead2 = help_DKc
let t2done = epochTime() - t2
# First run
# Parsecfg
var dict = newConfig()
dict.setSectionKey("help","DKc","Hjælp")
var dead3 = ""
let t3 = epochTime()
for i in countup(1, 1000):
#echo dict.getSectionValue("help","DKc")
dead3 = dict.getSectionValue("help","DKc")
let t3done = epochTime() - t3
echo "Tables: " & $t1done
echo "Constant: " & $t2done
echo "Parsecfg: " & $t3done
# Tables: 0.000804901123046875
# Constant: 0.0003900527954101562
# Parsecfg: 0.001749038696289062