Mate, in this code, since it does not have any third party dependency (like IO requests) speed is depend on the number of instructions.
So in the first program as you mentioned, number of instructions are higher than the second one and it takes more time than the second one. you can check this...