Skip to content

Commit a055046

Browse files
committed
Update for multiple execution of each problem
1 parent 3041b4a commit a055046

File tree

16 files changed

+56
-43
lines changed

16 files changed

+56
-43
lines changed

bench.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ for dir in *; do
77
COMMANDS=("python ${dir}.py")
88
COMMANDS+=($dir)
99
cd "$dir"
10+
echo
1011
echo "Benchmarking $dir"
12+
echo "======================"
1113
$COMPILE
1214
$BENCH "${COMMANDS[@]}"
1315
cd ..

problem-1/problem-1

4.28 MB
Binary file not shown.

problem-1/problem-1.mojo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ fn lengthOfLastWord(enterword: String):
1010

1111

1212
fn main():
13-
var input_string = "Hello World"
14-
lengthOfLastWord(input_string)
13+
for _ in range(100000):
14+
lengthOfLastWord("Hello World")

problem-1/problem-1.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
def lengthOfLastWord(enterword):
2-
1+
def length_of_last_word(enterword):
2+
33
count = 0
44

55
for i in range(len(enterword)-1, -1, -1):
@@ -11,7 +11,8 @@ def lengthOfLastWord(enterword):
1111
print("Length of last word", count)
1212

1313
def main():
14-
input_string = "Hello World"
15-
result = lengthOfLastWord(input_string)
16-
17-
main()
14+
[length_of_last_word("Hello World") for _ in range(100000)]
15+
16+
17+
if __name__ == "__main__":
18+
main()

problem-2/problem-2

4.28 MB
Binary file not shown.

problem-2/problem-2.mojo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ fn checkRecord(attendance_record: String) -> Bool:
2323

2424

2525
fn main():
26-
var value = checkRecord("PAALP")
26+
for _ in range(100000):
27+
_ = checkRecord("PAALP")

problem-2/problem-2.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
def checkRecord(attendance_record):
2-
1+
def check_record(attendance_record):
2+
33
attendance_record_str = str(attendance_record)
44

55
absent_count = 0
66
late_count = 0
77

88
for i in range(len(attendance_record_str)):
9-
9+
1010
if attendance_record_str[i] == 'A':
1111
absent_count += 1
1212
late_count = 0
@@ -22,8 +22,11 @@ def checkRecord(attendance_record):
2222
print("The attendance record is acceptable.")
2323
return True
2424

25+
2526
# Main function
2627
def main():
27-
checkRecord("PAALP")
28-
29-
main()
28+
[check_record("PPALLP") for _ in range(100000)]
29+
30+
31+
if __name__ == "__main__":
32+
main()

problem-3/problem-3

4.28 MB
Binary file not shown.

problem-3/problem-3.mojo

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ fn makeGood(s: String):
1717
print(result)
1818

1919
fn main():
20-
var input_str = "leEeetcode"
21-
makeGood(input_str)
22-
23-
#print("After making the string good:", result)
20+
for _ in range(1000000):
21+
makeGood("leEeetcode")

problem-3/problem-3.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
def makeGood(s):
1+
def make_good(s):
22
result = ""
33

44
i = 0
55
while i < len(s):
6-
6+
77
if i < len(s) - 1 and abs(ord(s[i]) - ord(s[i + 1])) == 32:
8-
8+
99
i += 2
1010
else:
11-
11+
1212
result += s[i]
1313
i += 1
1414

1515
return result
1616

17+
1718
def main():
18-
19-
input_str = "leEeetcode"
20-
output_str = makeGood(input_str)
21-
print(output_str)
19+
[make_good("leEeetcode") for _ in range(1000000)]
20+
2221

23-
main()
22+
if __name__ == "__main__":
23+
main()

0 commit comments

Comments
 (0)