> Is there any way I can leverage multiple cores of the target system to 
> maximize efficiency?

Yes, but efficiency can't be guaranteed. The workload must be sufficiently 
large for the cores to most all of their time processing it, or else the 
bottleneck will fall into the creation and destruction of threads, which will 
make it slower than the single threaded version. See 
[https://forum.nim-lang.org/t/5909](https://forum.nim-lang.org/t/5909) for an 
example of inefficiency caused by threading.

But back to the main question:

> Is it possible to share a Hashmap between threads?

Yes, you can with this: 
[https://nim-lang.org/docs/sharedtables.html](https://nim-lang.org/docs/sharedtables.html),
 note that as the access to the table have to be placed behind a lock, this 
will actually decrease ability to do multiple core efficiently as they will 
spend most of the time waiting to have access to the table.

Your main bottleneck would be this snippet:
    
    
    paramStr(1).open().readAll().splitLines().ytz()
    
    
    Run

What would happen is that you `open` a file, then a cycle of string allocation 
& read syscalls until the file is read, then all of the resulting string is 
parsed for new lines, where each line will have their own strings allocated for 
the resulting seq then eventually passed to `ytz`. And all of that is really 
really slow.

What would be faster is to read from the file line-by-line. This can be done 
via the `lines` iterator, which will skip the huge overhead from reading then 
parse from the start to split by line, as the iterator returns each line as 
it's read from the disk.

Reply via email to