1#!/usr/local/bin/python3.8 2# -*- coding: utf-8 -*- 3 4 5import cProfile 6import pstats 7 8from mathics.core.definitions import Definitions 9from mathics.core.evaluation import Evaluation 10 11definitions = Definitions(add_builtin=True) 12 13 14def prepare(): 15 pass 16 17 18result = None 19 20 21def run(): 22 global result 23 # prompt = '(1+a)(1+b)(1+c)(1+d)(1+e)//Expand' 24 # prompt = 'f/@Range[20000];' 25 # prompt = 'Plus @@ Range[50000]' 26 # prompt = 'Range[100000];' 27 try: 28 # prompt = 'SetAttributes[v, Flat]; v[x_]:={x}; v[a,b]' 29 # prompt = """(Plus@@Symbol/@CharacterRange["a","z"])^2//Expand;""" 30 # prompt = ( 31 # 'Plus@@f/@Symbol/@StringJoin/@Tuples[CharacterRange["a","z"],2]') 32 # prompt = 'FullForm[Nest[1+Sqrt[1+#]&, x, 20]]' 33 # prompt = '1+2' 34 prompt = "DensityPlot[x*y,{x,-1,1},{y,-1,1}]" 35 evaluation = Evaluation(definitions, format="xml") 36 result = evaluation.parse_evaluate(prompt) 37 except KeyboardInterrupt: 38 result = "INTERRUPTED" 39 40 41def _profile(): 42 global result 43 prepare() 44 cProfile.run("run()", "profile") 45 p = pstats.Stats("profile") 46 p.sort_stats("cumulative").print_stats(50) 47 p.print_callees(20) 48 49 50if __name__ == "__main__": 51 _profile() 52