Revision ef1e46010f6547419301c519666a1aece49b92d1 authored by Alon Zakai on 29 January 2014, 18:28:48 UTC, committed by Alon Zakai on 29 January 2014, 18:28:48 UTC
1 parent b67e161
Raw File
scan_js.py
'''
Finds why a .js file is large by printing functions by size
'''

import os, sys

funcs = []
i = 0
inside = None
for line in open(sys.argv[1]):
  i += 1
  if line.startswith('function _'):
    inside = line.replace('function ', '').replace('\n', '')
    start = i
  elif inside and line.startswith('}'):
    funcs.append((inside, i-start))
    inside = None

print '\n'.join(map(lambda func: str(func[1]) + ':' + func[0], sorted(funcs, key=lambda func: -func[1])))

back to top