Skip to content

Instantly share code, notes, and snippets.

@msztolcman
Created December 5, 2016 06:31
Show Gist options
  • Save msztolcman/4bac16a51114fdbf8863eacd3a4dc675 to your computer and use it in GitHub Desktop.
Save msztolcman/4bac16a51114fdbf8863eacd3a4dc675 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals
import os, os.path
import re
import sys
from pprint import pprint, pformat
import random
import time
size = 5000000
st = time.time()
a = [random.randint(1, size) for _ in xrange(size)]
print("Random list init", time.time() - st)
st = time.time()
a = [i for i in range(size)]
print("Range list init", time.time() - st)
# Results for Py2:
# Random list init 8.04576992989
# Range list init 0.624060153961
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment