Comparing c and java programs runtime -


I had a job interview today, we were given a programming question, and it was asked to solve it using C / C ++ / Java. , I solved it in Java and its runtime was 3 seconds (the test was 16000 lines, and the person with us said that the time to walk was appropriate), another person solved it in C and the runtime was 0.25 seconds, So I was thinking, 12 is a factor of general?

Edit: As I said, I do not think there was really much for algorithm variation, except that in a small matter, anyway, this protocol was that we had to implement : A (client) and B (server) dialogue according to some Protocol P, the messages are examined before checking their validity, the protocol is defined by its position and text message, when it is a well State, had only one legitimate message in all states, which could be sent except to a state where there were 10 messages that can be sent, there has also been defined by the protocol transition 5 State Es and states. So what did I do with the state, out of which 10 different messages could be sent, their string value was being stored in an ArrayList container, when I needed to check the message validity in the respective state I have checked that if arrayList.contains (sentMessageStr); I think that the complexity of this operation is O (n), although I think there is some underlying optimization for this operation in Java, though now I'm thinking about it, I think I should use a Hashket container. I think implementing those predefined legal strings would have to implement lexifography and a binary search function in an array.

Thank you

I think it is possible that JVM did that 3 seconds Took an important part, just to load. Try running your Java version on the same machine 5 times in a row or try to run both on 500 times larger datasets. I suspect that you will see an important continuous latency for the Java version which goes in runtime minutes.


Comments