time

perf_counter()-start giving weird result

perf_counter()-start giving weird result Question: I was building my own version of the timeit function, which returns the amount of time it takes to run a function n times. However, when I ran it with a sample input, I received the following output, which doesn’t seem right, as it ran very quickly. 9.400071576237679e-06 My code: …

Total answers: 1

How can i make this python code quicklier?

How can i make this python code quicklier? Question: How can i make this code more quicklier? def add_may_go(x,y): counter = 0 for i in range(-2,3): cur_y = y + i if cur_y < 0 or cur_y >= board_order: continue for j in range(-2,3): cur_x = x+j if (i == 0 and j == 0) …

Total answers: 3

Why is this JAX jitted function so much slower than the non-jitted JAX version?

Why is this JAX jitted function so much slower than the non-jitted JAX version? Question: I’m in the process of rewriting some code from pure Python to JAX. I have a function that I need to call a lot. Why is the jitted version of the following function so much slower than the non-jitted version? …

Total answers: 1

Python dataframe – resample timestamps, group by hour, but keep the start and end datetime

Python dataframe – resample timestamps, group by hour, but keep the start and end datetime Question: I have a DataFrame containing timestamps and values. list = [‘2020-04-22 13:29:00+00:00′,’2020-04-22 13:31:00+00:00′,’2020-04-22 13:32:00+00:00′,’2020-04-22 13:33:00+00:00′,’2020-04-22 13:34:00+00:00′,’2020-04-22 13:35:00+00:00′,’2020-04-22 13:36:00+00:00′,’2020-04-22 13:54:00+00:00′,’2020-04-22 13:55:00+00:00′,’2020-04-22 13:56:00+00:00′,’2020-04-22 13:57:00+00:00′,’2020-04-22 13:58:00+00:00′,’2020-04-22 13:59:00+00:00′,’2020-04-22 14:00:00+00:00′,’2020-04-22 14:01:00+00:00′,’2020-04-22 14:02:00+00:00′,’2020-04-22 14:03:00+00:00′,’2020-04-22 14:04:00+00:00′,’2020-04-22 14:05:00+00:00′,’2020-04-22 14:06:00+00:00′,’2020-04-22 14:49:00+00:00′,’2020-04-22 14:50:00+00:00′,’2020-04-22 14:51:00+00:00′,’2020-04-22 14:52:00+00:00′,’2020-04-22 14:53:00+00:00′,’2020-04-22 14:54:00+00:00′,’2020-04-22 14:55:00+00:00′,’2020-04-22 14:56:00+00:00’,’2020-04-22 …

Total answers: 2

Take user input in HH:MM and convert it to a float

Take user input in HH:MM and convert it to a float Question: I am trying to create a program where I add number of hours worked into a list then sum inputs and calculate overtime for hours worked above 40 from tkinter import * #Tkinter window win = Tk() win.geometry("500×500") win.title("Attempt") win.resizable(False,False) my_list =[] #Get …

Total answers: 3

How to convert a difference in timestamp to miliseconds?

How to convert a difference in timestamp to miliseconds? Question: I have two dates in timestamp and their difference is dt 0.006951093673706055 dt is: (1669983551.287477-1669983551.280526) I want to generate several dates (in datetime) with that difference Now normally I would do date_list = [datetime.now() + datetime.timedelta(milliseconds=x) for x in range(n)] but here timedelta uses the …

Total answers: 1

Pandas timedelta subtraction returns different values when operands are swapped

Pandas timedelta subtraction returns different values when operands are swapped Question: I have two pd.Timestamp objects: t1 = pd.Timestamp(2022-11-02 10:44:22.700000) t2 = pd.TImestamp(2022-11-02 10:44:22.760000) Now I want to get the timedelta for those two values. If I do it like this: t2 – t1 I get Timedelta(‘0 days 00:00:00.060000’), which is the expected behaviour, but …

Total answers: 1

Microsecond do not work in Python logger format

Microsecond do not work in Python logger format Question: For some reason my Python logger does not want to recognize microseconds format. import logging, io stream = io.StringIO() logger = logging.getLogger("TestLogger") logger.setLevel(logging.INFO) logger.propagate = False log_handler = logging.StreamHandler(stream) log_format = logging.Formatter(‘%(asctime)s – %(name)s – %(levelname)s – %(message)s’,"%Y-%m-%d %H:%M:%S.%f %Z") log_handler.setFormatter(log_format) logger.addHandler(log_handler) logger.info("This is test info …

Total answers: 2

Trying to sleep milliseconds time.sleep(0.001) not working as expected, alternatives?

Trying to sleep milliseconds time.sleep(0.001) not working as expected, alternatives? Question: I’m trying to run a function approximately 200 times a second (give or take +- 50). When using time.sleep(0.005), I find that it sleeps for much longer. I understand that time.sleep is not accurate, but my use case doesn’t need much accuracy either. I …

Total answers: 1