Different runtimes and memory usage for same program?

image

I have written a code to convert a roman numeral to an integer(problem #7: Roman to Integer) in python3, and each time I submit the code, I get a different runtime and memory usage, for the same code every time. Why is that?

    def romanToInt(s: str) -> int:
        romanNums = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}
        number = 0
        x = len(s) - 1
        while x >= 0:
            if romanNums[s[x]] > romanNums[s[x-1]] and x != 0:
                number += romanNums[s[x]] - romanNums[s[x-1]]
                x -= 2
            else:
                number += romanNums[s[x]]
                x -= 1
        return number
Comments (0)