You can either implement the walk method as an anonymous function within
the function that you open the file, closing over the os.File variable or
implement your walk function as a method on a type containing the reader.
On Wednesday, July 17, 2013 8:21:57 AM UTC-7, Xan wrote:

Thanks for comments, good.

El dimarts 16 de juliol de 2013 18:15:07 UTC+2, Stephen Day va escriure:
There are two techniques that immediately stand out as problematic:

1. The output file is being opened multiple times. This is probably
costly and definitely unnecessary. Implement VisitFile as a method on a
struct with a file member or implement it as a closure in main so that the
same Writer can be used on each call.
Can you help me on that? How can open the file once before main procedure
(filepath.Walk) and having it like global variable?

2. When Message is written to the output file with io.WriteString method,
"content" is cast to a string, causing an unnecessary copy from the []byte
returned by json.Marshal. Just directly call f.Write with the buffer
returned by json.Marshal.
The second is implemented:
I hope this gets you started!
On Tuesday, July 16, 2013 8:40:40 AM UTC-7, Xan wrote:


I have this code [
that simply calculates the hash (sha256sum) of each file of an specific
directory and outputs a JSON file with results (adding other info like
size, ... of the files).

I know it's CPU intensive (sha256) but I want to know if it's possible
to be more faster and consume less memory (it consumes fewer memory)

Can someone audit my code?

Thanks in advance,
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 12 of 14 | next ›
Discussion Overview
groupgolang-nuts @
postedJul 16, '13 at 3:40p
activeJul 20, '13 at 8:52p



site design / logo © 2021 Grokbase