Calculate exact character\string height in javascript

Width is easy: canvas’s context has a built in metric for measuring text width. // this will measure text width context.font=”14pt Verdana”; var m=context.measureText(yourText); var theWidth=m.width; Height is more difficult because measureText doesn’t compute height. You can often use the font size to approximate the height–that’s what I do. But if you really need more … Read more

How do I measure request and response times at once using cURL?

From this brilliant blog post… https://blog.josephscott.org/2011/10/14/timing-details-with-curl/ cURL supports formatted output for the details of the request (see the cURL manpage for details, under -w, –write-out <format>). For our purposes we’ll focus just on the timing details that are provided. Times below are in seconds. Create a new file, curl-format.txt, and paste in: time_namelookup: %{time_namelookup}s\n time_connect: … Read more

How do I measure elapsed time in Python?

Use time.time() to measure the elapsed wall-clock time between two points: import time start = time.time() print(“hello”) end = time.time() print(end – start) This gives the execution time in seconds. Another option since Python 3.3 might be to use perf_counter or process_time, depending on your requirements. Before 3.3 it was recommended to use time.clock (thanks … Read more