Joseph Jude

Consult . Code . Coach

Timing code execution in Swift, Python & Typescript


code . swift . tsc . python

Time to time, you need to check the execution time of a code block. Here are the snippets for Swift, Python & Typescript.

Swift

import Foundation
var start = NSDate()

// code block to measure

var end = NSDate()
let timeInterval: Double = end.timeIntervalSinceDate(start)
print("Time to execute \(timeInterval) seconds")

Python

import time
start_time = time.time()

# code block to measure

print("Time to execute %s seconds" % (time.time() - start_time))

Typescript

var start = new Date().getTime();

// code block to measure

var end = new Date().getTime();
console.log(end - start);


Like the post? Retweet it. Got comments? Reply.

Timing code execution in #swift, #python & #typescript by @jjude https://t.co/OsJABmHPBq

— Joseph Jude (@jjude) December 16, 2016
Share this on: Twitter / /

Comments

comments powered by Disqus