How to use timeit module

If you want to use timeit in an interactive Python session, there are two convenient options: Use the IPython shell. It features the convenient %timeit special function: In [1]: def f(x): …: return x*x …: In [2]: %timeit for x in range(100): f(x) 100000 loops, best of 3: 20.3 us per loop In a standard … Read more

Python’s time.clock() vs. time.time() accuracy?

As of 3.3, time.clock() is deprecated, and it’s suggested to use time.process_time() or time.perf_counter() instead. Previously in 2.7, according to the time module docs: time.clock() On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends … Read more

In Ruby on Rails, what’s the difference between DateTime, Timestamp, Time and Date?

The difference between different date/time formats in ActiveRecord has little to do with Rails and everything to do with whatever database you’re using. Using MySQL as an example (if for no other reason because it’s most popular), you have DATE, DATETIME, TIME and TIMESTAMP column data types; just as you have CHAR, VARCHAR, FLOAT and … Read more

How do you convert epoch time in C#?

UPDATE 2020 You can do this with DateTimeOffset DateTimeOffset dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(epochSeconds); DateTimeOffset dateTimeOffset2 = DateTimeOffset.FromUnixTimeMilliseconds(epochMilliseconds); And if you need the DateTime object instead of DateTimeOffset, then you can call the DateTime property DateTime dateTime = dateTimeOffset.DateTime; Original answer I presume that you mean Unix time, which is defined as the number of seconds since … Read more

What is the standard way to add N seconds to datetime.time in Python?

You can use full datetime variables with timedelta, and by providing a dummy date then using time to just get the time value. For example: import datetime a = datetime.datetime(100,1,1,11,34,59) b = a + datetime.timedelta(0,3) # days, seconds, then other fields. print(a.time()) print(b.time()) results in the two values, three seconds apart: 11:34:59 11:35:02 You could … Read more

Why is 1/1/1970 the “epoch time”?

Early versions of unix measured system time in 1/60 s intervals. This meant that a 32-bit unsigned integer could only represent a span of time less than 829 days. For this reason, the time represented by the number 0 (called the epoch) had to be set in the very recent past. As this was in … Read more

How to recursively find and list the latest modified files in a directory with subdirectories and times

Try this one: #!/bin/bash find $1 -type f -exec stat –format ‘%Y :%y %n’ “{}” \; | sort -nr | cut -d: -f2- | head Execute it with the path to the directory where it should start scanning recursively (it supports filenames with spaces). If there are lots of files it may take a while … Read more