« first day (427 days earlier)      last day (506 days later) » 

user457812
2:20 AM
Boom.
 
user457812
Curd apps.
 
5:32 AM
Hi, go professionals. Would be super grateful if someone would be kind enough to code review codereview.stackexchange.com/q/88307/30711 the slowlyness of my go code.
 
user457812
Tried running it through a profiler?
 
user457812
'Cause the code's clearly different.
 
the code is clearly different, but it does the same thing. I do not know how to run it though a profiler
 
user457812
I'm also not entirely sure how you're getting 2.6 seconds.
 
on hackerrank once you submit the code, you see its time of execution for each of their tests. The slowest test takes 2.6 seconds and the same test in python takes 0.08 seconds
 
user457812
5:38 AM
Ok, how can that be reproduced by everyone looking at your code?
 
user457812
i.e., without doing whatever hackerrank is
 
I mentioned in the code, that if someone needs the testcase I will try to upload it. Apparently you need a testcase and in a couple of seconds I will give it to you.
 
user457812
Pretty much.
 
user457812
Anything involving timing more or less boils down to "how do I reproduce this?"
 
user457812
My thought is it's probably going to be a matter of looking at your use of a map.
 
5:56 AM
here is a link to a test case: zeta-uploader.com/642815386
 
user457812
So, I've got it to the point, at least on hackerrank, where the longest runtime is 0.01s for test #5
 
so you were able to achieve 0.01s on test 5 with my code? Or have you somehow modified my code?
 
user457812
@SalvadorDali Without profiling — because I need to apply a patch to my kernel before I can get any meaningful results via go pprof (if you're on Linux or FreeBSD, you should) — there are two easy things to pick on in your code.
 
user457812
 
user457812
It'll get you up to speed on basic profiling.
 
user457812
6:04 AM
I got it to 0.01s with my own implementation of your code. About the only thing still intact is your for loop in the main() function.
 
can you please show me your implementation?
either on go playground play.golang.org or as an answer to my code-review question
 
user457812
That in mind, let's talk about two important things: first, fmt.Scanf is slow. Second, map[uint8]bool is an inefficient data structure for this problem.
 
user457812
I'll post it as an answer to the CR question later, maybe, if I have time to do a write-up of the differences
 
this is good. So what is faster than fmt.Scanf and what can be more efficient than map here. Would appreciate your answer.
 
user457812
I'm going back and adding error-checking to my implementation just to keep it sane, so that'll be a second
 
user457812
6:09 AM
Anyway, data-structures: map isn't a set, and for this particular set, we have a really limited scope for the problem: latin characters.
 
user457812
That means that the set will only contain integers in a very small range, and more importantly that this range is entirely within 26 bits.
 
user457812
So an ideal data-structure for this is probably a bitset, and maybe just a single integer.
 
user457812
So, you can ditch the map and just do bitwise tests to see if there's any intersection between two strings.
 
I thought about array of bits (I think that it would be too problematic to update the integer)
 
user457812
play.golang.org/p/kfDy7HWJK3 ← Anyway, that's the final form of the code with error checking.
 
user457812
6:18 AM
The two largest performance changes are down to not using fmt.Scanf, because that's inherently expensive (involves parsing a format string, using reflection to store a result in the scan output[s], etc. — overall not a good model if you're only concerned about performance), and not using map[uint8]bool, because that's a wasteful data structure for the problem.
 
user457812
The important thing for replacing the map in there is the charSet type, which is literally just a thing providing an interface to an int.
 
user457812
In other words, it's dumb as a rock, but given the limited scope of the problem, it's also really efficient and a good way to avoid needless map allocations and such.
 
user457812
Replacing fmt.Sprintf is just reading the initial count and parsing it and then reading each line as a byte slice via a buffered reader. No time wasted on parsing format strings or initializing a scanner or anything else.
 
user457812
There are probably faster implementations, but that's the dumbest, simplest way to beat Python.
 
thank you nil. Do you mind if I will link this conversation to my question?
 
user457812
6:26 AM
Basically, you have control over data structures and how you work with data in Go. You won't have the same level of control in Python. Easiest way to beat Python is take advantage of it.
 
user457812
That's fine.
 
user457812
That being said, you can probably also use the same implementation in Python and it might also get some performance improvements as a result.
 
user457812
7:06 AM
@SalvadorDali Wrote an answer to your question. Let me know if there's anything missing, since it's currently midnight and I'm tired.
 
Hi folks!
 
user457812
'Lo.
 
How goes it fellow gopher?
 
user457812
More or less fine. Going to be deploying more Go services at work tomorrow.
 
Thats pretty awesome! :D
 
user457812
7:16 AM
I'm beginning to think we should start mentioning in our job postings that we use node.js and Go just to attract those sorts of people.
 
user457812
Much as I don't like node.js, I'd rather get more people who are flexible enough to work with either
 
node guys are like php guys
the quality is all over the place
 
user457812
Yeah, which is why I ask data structures questions when interviewing people
 
user457812
Not like one-true-answer questions but more open-ended ones to see what people pull out of their heads for that problem.
 
7:29 AM
@nil thanks, already upvoted it.
 
7:54 AM
@nil I just tend to look at their projects. In my experience, interviews don't work so well with people who are not used to having what they say examined under a microscope
Really good interviewers can make you feel very comfortable, but most are arseholes.
 
user986408
8:19 AM
hey fellas
 
user986408
is there a way to optimize this? play.golang.org/p/bt0OOKpN6s
 
user986408
the handlerfunc is so bloated but i don't know how to inject the render object besides using the closure
 
user457812
@GamesBrainiac I'd look at them, but there's a surprising dearth of projects, GitHub repos, etc. among applicants so far. Easy way to get ahead: have cool GitHub repos.
 
user457812
I suspect the open source culture I grew up in still isn't all that common in spite of its growth.
 
1:46 PM
hi
nyone there ?
 
2:05 PM
Hola gentlemen :)
@abhi Hiya :)
@nil lo brother!
 
 
2 hours later…
user457812
4:01 PM
@GamesBrainiac 'Lo
 
4:30 PM
@nil So, whats up?
 
 
1 hour later…
user457812
5:39 PM
Deployments.
 
user457812
5:53 PM
So far so good.
 
user457812
Also, my first answer on codereview.se got like 10 upvotes.
 

« first day (427 days earlier)      last day (506 days later) »