Code execution on online judges

I have tried following things:

  1. I submitted a correct solution and the “Time” in “My Submissions” tab was, say x.
  2. Then, I edited the code to run for say the first half test cases correctly and print a character(not present in any correct answer) for later half of the test cases. Now, the “Time” was y. Also, y was lesser than x significantly. I thought execution stopped when it encountered the first wrong input.
  3. I used the assert function in my code so as to check whether my code was running for all the test cases and I was surprised to find YES it was! I used this sort of code:
while(t--){
    assert(t>0);
}

where, t is the number of test cases.

So, it means that the code returned a run time error when running for the last test case (when t=0). This in turns means that my code was executed for each and every test case.

Now, my question is that does not the online judges stop a code when the first wrong output is met? If yes, then how come there is a difference in time in scenarios 1 and 2 and how is the time calculated? I am interested in knowing how and when output files are compared and when the execution of a code is stopped.