Nonsense not to say, directly on the source
1 #Decorative Device2 Import Time3 defRuntime (func):4 defInner_func (*args, * *Kwargs):5StartTime =time.time ()6res = func (*args)7 Print('Run time:{}'. Format (Time.time ()-startTime))8 returnRes9 returnInner_funcTen One #testing the type function A defTest_type (*args, * *Kwargs): -types = [Str,int,float,bool,tuple,list,set,dict]#define a list of common types -type_dict= {}#defines a return set type dictionary the ifArgs#determine if there are parameters - forArginchArgs#Traversal Parameters - forTinchTypes#Traversal Type - ifType (ARG) = = T:#match types with type function +TYPE_DICT[STR (arg)] = t#convert arg to key name, T as key value into dictionary - Break #Interrupt Loop + returntype_dict A at #testing the Isinstance function - defTest_isinstance (*args, * *Kwargs): -Types =[Str,int,float,bool,tuple,list,set,dict] -type_dict= {} - ifargs: - forArginchargs: in forTinchtypes: - ifIsinstance (ARG, t) = = True:#match type with isinstance function toTYPE_DICT[STR (ARG)] =T + Break - returntype_dict the * @runtime $ defFor_loop_type (*args, * *Kwargs):Panax Notoginseng forIinchRange (100000):#Loop call Test_type function 100,000 times - Test_type (args, Kwargs) the + @runtime A defFor_loop_isinstance (*args, * *Kwargs): the forIinchRange (10000):#Loop call test_isinstance function 100,000 times + test_isinstance (args, Kwargs) - $ $ #For_loop_type (1,2,3,4,5,6,7,8,9,2,0,true, (' A ', ' B ', ' C '), {' A ', ' B ', ' C '},[' A ', ' B ', ' C '],{' name ': ' Tom ', ' age ': 20 }) - #for_loop_isinstance (1,2,3,4,5,6,7,8,9,2,0,true, (' A ', ' B ', ' C '), {' A ', ' B ', ' C '},[' A ', ' B ', ' C '],{' name ': ' Tom ', ' Age ': $})
Small partners to test it, I measured the data show that isinstance than the type of high efficiency is not a level, after the test you have to know.
Python Fundamentals: Test the type and isinstance that faster