Skip to content

Instantly share code, notes, and snippets.

View Kush1101's full-sized avatar
🤔
<Comprehending>

Kushagra Bansal Kush1101

🤔
<Comprehending>
View GitHub Profile
import time
def function_1(*parameters):
#do something
# return value
def function_2(*parameters):
#do something
#return value
#measuring time taken by function_1
start_of_f1 = time.time()
import time
start_time = time.time()
"""
Some Code
"""
end_time = time.time()
print(f"The execution time is: {end_time-start_time}")
def bubble_sort(arr):
for i in range(len(arr)):
for j in range(0, len(arr) - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr
def make_random_array():
from random import randint
@Kush1101
Kush1101 / timeit_example1.py
Created September 1, 2020 06:40
Medium_timeit
import timeit
#This code will be executed only once, before stmt.
setup_code = "from math import sqrt"
#This code will be executed as specified by the parameter 'number'
stmt_code = "sum(sqrt(x) for x in range(1,10000))"
iterations = 10000
time = timeit.timeit(stmt = stmt_code, setup = setup_code, number = iterations)
def MiniStringFuck_interpreter(code):
memory = 0 #initialize the memory cell value at zero
output="" #output string
for char in code:
if char=="+":
memory+=1
if memory>255:
memory=memory%256
if char==".":
output+=chr(memory)
MiniStringFuck_interpreter(+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.)
#>> Prints all the uppercase English Alphabets.
import time
import sys
a=time.time()
def same(n):
return sorted(str(n))==sorted(str(2*n)) ==\
sorted(str(3*n))==sorted(str(4*n))==sorted(str(5*n))
"""
Here I have tried to optimize the performance by chekcing only the numbers from n to 2n
"""
Problem 37 on project Euler
https://projecteuler.net/problem=37
"""
"""
Note: This code takes about 2 seconds to execute. You ca reduce this time by adapting to
faster methods of checking if a number is prime or not like the Seive method.
But this code is intended to be beginner friendly so I have used the simple way to check for primes.
"""