Best Python code snippet using pytest-benchmark
datetime_lib.py
Source:datetime_lib.py
1import time as _time2from datetime import *3import tijd4from errors import *5import sys6t = datetime.today()7import time as _time8def time_zone():9 LOCAL_TIMEZONE = datetime.now(timezone.utc).astimezone().tzinfo10 timez_zone = str(LOCAL_TIMEZONE)11 return timez_zone12def time_and_date_now(waarde):13 now = datetime.now()14 15 if waarde.upper() == 'TONEN_TIJD':16 print("de tijd en datum nu is :", end=' ')17 print(now.strftime("%Y-%m-%d %H:%M:%S"), end=' en de tijd in sec sinds 1970 is: ')18 print(_time.time())19 RETURN = str(now.strftime("%Y-%m-%d %H:%M:%S")) + ' tijd sinds 1970: ' + str(_time.time())20 return RETURN21 elif waarde.upper() == 'TONEN_NU':22 print("de tijd en datum nu is :", end=' ')23 print(now.strftime("%Y-%m-%d %H:%M:%S"))24 return now.strftime("%Y-%m-%Y %H:%M:%S")25 elif waarde.upper() == 'RETURN_TIJD':26 RETURN = str(now.strftime("%Y-%m-%d %H:%M:%S")) + ' tijd sinds 1970: ' + str(_time.time())27 return RETURN28 29 elif waarde.upper() == 'RETURN_NU':30 return [int(now.strftime("%Y")), int(now.strftime("%m")), int(now.strftime("%d")), int(now.strftime("%H")), int(now.strftime("%M")), int(now.strftime("%S"))]31 else:32 print('ongeldig commando')33def month(ma ,taal):34 now = datetime.now()35 nummer = now.strftime('%m')36 nummer = int(nummer)37 nummer = nummer - 1 #omdat python begint bij lijsten het tellen vanaf 0 inplaats van 1 en het is dan niet 1 tm 12 maar 0 tm 1138 RETURN = True39 if ma.lower() == 'nu': man = True40 else: man = False41 if taal.upper() == 'NL_AF': # NL_AF is een afkorting van NEDERLANDSE_AFKORTINGEN42 maanden = ['jan', 'feb', 'ma', 'ap', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec']43 elif taal.upper() == 'NL':44 maanden = ['januari', 'februarie', 'maaart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december']45 elif taal.upper() == 'FR':46 maanden = ['Janvier', 'Février', 'Mars', 'Avril', 'mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Décembre']47 elif taal.upper() == 'FR_AF': #FR_AF is een afkorting van FRANSE_AFKORTINGEN48 maanden = ['Janvier', 'Fév', 'Mar', 'Avr', 'mai', 'Juin', 'Juil', 'Août', 'Sep', 'Oct', 'Déc']49 elif taal.upper() == 'ENG':50 maanden = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']51 elif taal.upper() == 'ENG_AF':52 maanden = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']53 else:54 RETURN = False55 raise AttributeError('Wrong argument given')56 if RETURN == True:57 if man == True:58 return maanden[nummer]59 else:60 return maanden61 62def day_today():63 print('counting from 1970')64 tijd = _time.time()65 tijd = tijd / 6066 tijd = tijd / 6067 tijd = tijd / 2468 tijd = int(tijd)69 70 return tijd71def day_today_year():72 73 tijd = _time.time()74 tijd = tijd / 6075 tijd = tijd / 6076 tijd = tijd / 2477 tijd = int(tijd)78 times = int(tijd / 365)79 min_ = times * 36580 schrik = int(times / 4)81 schrik = schrik - 1# omdat het jaar 2000 geen schrikkel jaar was82 tijd = tijd - (min_ + schrik)83 return tijd84def day(taal):85 taal = taal.lower()86 if taal == 'eng':87 wochentag = ["Monday", "Tuesday", "Wednesday",88 "Thursday", "Friday", "Saturday", "Sunday"]89 elif taal == 'nl':90 wochentag = ["maandag", "dinsdag", "woensdag",91 "donderdag", "vrijdag", "zaterdag", "zondag"]92 93 elif taal == 'fr':94 wochentag = ["lundi", "mardi", "mercredi",95 "jeudi", "vendredi", "samedi", "dimanche"]96 elif taal == 'de':97 wochentag = ["Montag", "Dienstag", "Mittwoch",98 "Donnerstag", "Freitag", "Samstag", "Sonntag"]99 else:100 wochentag = ["error", "error", "error",101 "error", "error", "error", "error"]102 103 return wochentag[t.weekday()]104def days(taal):105 taal = taal.lower()106 if taal == 'eng':107 wochentag = ["Monday", "Tuesday", "Wednesday",108 "Thursday", "Friday", "Saturday", "Sunday"]109 elif taal == 'nl':110 wochentag = ["maandag", "dinsdag", "woensdag",111 "donderdag", "vrijdag", "zaterdag", "zondag"]112 113 elif taal == 'fr':114 wochentag = ["lundi", "mardi", "mercredi",115 "jeudi", "vendredi", "samedi", "dimanche"]116 elif taal == 'de':117 wochentag = ["Montag", "Dienstag", "Mittwoch",118 "Donnerstag", "Freitag", "Samstag", "Sonntag"]119 else:120 wochentag = ["error", "error", "error",121 "error", "error", "error", "error"]122 123 return wochentag124def day_to(dag):125 var = tijd.dagen_tot(dag)126 return var127def times_and_days_pam():128 from time import gmtime, strftime129 import time as _time130 tijd_gmt = _time.strftime("%a, %d %b %Y %I:%M:%S %p %Z", _time.gmtime())131 tijd_local = strftime("%a, %d %b %Y %I:%M:%S %p %Z\n")132 tijd_int_local = [int(strftime("%d")), int(strftime("%m")), int(strftime("%Y")), int(strftime("%H")), int(strftime("%M")), int(strftime("%S"))]133 tijd_int_gmt = [int(_time.strftime("%d", _time.gmtime())), int(_time.strftime("%m", _time.gmtime())), int(_time.strftime("%Y", _time.gmtime())), int(_time.strftime("%H", _time.gmtime())), int(_time.strftime("%M", _time.gmtime())), int(_time.strftime("%S", _time.gmtime()))]134 return [tijd_gmt, tijd_int_gmt, tijd_local, tijd_int_local]135def times_pam():136 from time import gmtime, strftime137 import time as _time138 tijd_gmt = _time.strftime("%I:%M:%S %p %Z", _time.gmtime())139 tijd_local = strftime("%I:%M:%S %p %Z")140 tijd_int_local = [int(strftime("%d")), int(strftime("%m")), int(strftime("%Y")), int(strftime("%H")), int(strftime("%M")), int(strftime("%S"))]141 tijd_int_gmt = [int(_time.strftime("%d", _time.gmtime())), int(_time.strftime("%m", _time.gmtime())), int(_time.strftime("%Y", _time.gmtime())), int(_time.strftime("%H", _time.gmtime())), int(_time.strftime("%M", _time.gmtime())), int(_time.strftime("%S", _time.gmtime()))]142 return [tijd_gmt, tijd_int_gmt, tijd_local, tijd_int_local]143def times():144 from time import gmtime, strftime145 import time as _time146 tijd_gmt = _time.strftime("%H:%M:%S(gmt)", _time.gmtime())147 tijd_local = strftime("%H:%M:%S")148 tijd_int_local = [int(strftime("%H")), int(strftime("%M")), int(strftime("%S"))]149 tijd_int_gmt = [int(_time.strftime("%H", _time.gmtime())), int(_time.strftime("%M", _time.gmtime())), int(_time.strftime("%S", _time.gmtime()))]150 return [tijd_gmt, tijd_int_gmt, tijd_local, tijd_int_local]151def times_and_days():152 from time import gmtime, strftime153 import time as _time154 tijd_gmt = _time.strftime("%d/%m/%Y %H:%M:%S %Z(gmt)", _time.gmtime())155 tijd_local = strftime("%d/%m/%Y %H:%M:%S %Z")156 tijd_int_local = [int(strftime("%d")), int(strftime("%m")), int(strftime("%Y")), int(strftime("%H")), int(strftime("%M")), int(strftime("%S"))]157 tijd_int_gmt = [int(_time.strftime("%d", _time.gmtime())), int(_time.strftime("%m", _time.gmtime())), int(_time.strftime("%Y", _time.gmtime())), int(_time.strftime("%H", _time.gmtime())), int(_time.strftime("%M", _time.gmtime())), int(_time.strftime("%S", _time.gmtime()))]158 return [tijd_gmt, tijd_int_gmt, tijd_local, tijd_int_local]159def days():160 from time import gmtime, strftime161 import time as _time162 tijd_gmt = _time.strftime("%d/%m/%Y")163 tijd_local = strftime("%d/%m/%Y")164 tijd_int_local = [int(strftime("%d")), int(strftime("%m")), int(strftime("%Y"))]165 tijd_int_gmt = [int(_time.strftime("%d", _time.gmtime())), int(_time.strftime("%m", _time.gmtime())), int(_time.strftime("%Y", _time.gmtime()))]166 return [tijd_gmt, tijd_int_gmt, tijd_local, tijd_int_local]167def days_local():168 from time import gmtime, strftime169 import time as _time170 tijd_gmt = _time.strftime("%d/%m/%Y")171 tijd_local = strftime("%d/%m/%Y")172 tijd_int_local = [int(strftime("%d")), int(strftime("%m")), int(strftime("%Y"))]173 tijd_int_gmt = [int(_time.strftime("%d", _time.gmtime())), int(_time.strftime("%m", _time.gmtime())), int(_time.strftime("%Y", _time.gmtime()))]174 return [tijd_local, tijd_int_local]175def times_local():176 from time import gmtime, strftime177 import time as _time178 tijd_gmt = _time.strftime("%H:%M:%S(gmt)", _time.gmtime())179 tijd_local = strftime("%H:%M:%S")180 tijd_int_local = [int(strftime("%H")), int(strftime("%M")), int(strftime("%S"))]181 tijd_int_gmt = [int(_time.strftime("%H", _time.gmtime())), int(_time.strftime("%M", _time.gmtime())), int(_time.strftime("%S", _time.gmtime()))]182 return [tijd_local, tijd_int_local]183def times_local_pam():184 ret = []185 ret.append(times_pam()[2])186 ret.append(times_pam()[3])187 return ret188def times_and_days_local():189 from time import gmtime, strftime190 import time as _time191 tijd_gmt = _time.strftime("%d/%m/%Y %H:%M:%S %Z(gmt)", _time.gmtime())192 tijd_local = strftime("%d/%m/%Y %H:%M:%S %Z")193 tijd_int_local = [int(strftime("%d")), int(strftime("%m")), int(strftime("%Y")), int(strftime("%H")), int(strftime("%M")), int(strftime("%S"))]194 tijd_int_gmt = [int(_time.strftime("%d", _time.gmtime())), int(_time.strftime("%m", _time.gmtime())), int(_time.strftime("%Y", _time.gmtime())), int(_time.strftime("%H", _time.gmtime())), int(_time.strftime("%M", _time.gmtime())), int(_time.strftime("%S", _time.gmtime()))]195 return [tijd_local, tijd_int_local]196def info():197 '''198tijd_en_datum_nu(value) = command to retutn or print199tijd_zone() = returns your time zone200times_and_days_pam(): returns the date and time of gmt and local201times_and_days() = returns date and time of gmt and local in 0 to 24 not in pm or am202times_pam() = returns the time gmt and local in pm or am203times() = returns the time gmt and local not in pm or am204days() = returns the day in gmt and in local205'''206def loop():207 pass208if __name__ == '__main__':209 try:210 print(time_zone())211 work = True212 except Exception as ex:213 print_warn(str(ex))214 work = False215 pass216 if work == True:217 print('func time_zone() state: working.\nmodule importable: True\n')218 ...
FILE2TSDB.py
Source:FILE2TSDB.py
1#!/usr/bin/env python2#-*- coding: utf-8 -*-3#import requests4import time5import json6from collections import OrderedDict7import pandas as pd8import sys9import os10import argparse11import shutil12import copy13from datetime import datetime14import pcs15import re16#ì¶ë ¥ ëë í 리 ì´ë¦ì outputì¼ë¡ ë³ê²½17# Result, changed JSON ë± , output ëë í 리 íë¶ì ì ì¥18# write ê´ë ¨ í¨ìë 모ëì ë°ë¡ íì¼ë¡ ë§ë¤ë©´ ì¢ìê²ê°ì19ARG= 50 #argment20'''21 convert Time to Epoch22'''23def checkTimeFormat(_time):24 # YYYY-MM-DD HH:MM:SS.SSS25 patt1=re.compile("\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}")26 # YYYY-MM-DD HH:MM:SS27 patt2=re.compile("\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}")28 # YYYY-MM-DDTHH:MM:SS.SSS29 patt3=re.compile("\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}")30 # YYYYmmddHHMMSS31 patt4 = re.compile("\d{14}")32 # time format íì¸ í epochë¡ convert33 if patt1.match(_time):34 # print("YYYY-MM-DD HH:MM:SS.SSS: ",_time)35 epoch=convertMilliTimeToEpoch(_time)36 elif patt2.match(_time):37 # print("YYYY-MM-DD HH:MM:SS: ",_time)38 epoch=convertTimeToEpoch(_time)39 elif patt3.match(_time):40 # print("YYYY-MM-DDTHH:MM:SS.SSS: ",_time)41 epoch=convertMilliTimeToEpoch_v2(_time)42 elif patt4.match(_time):43 # print("YYYYmmddHHMMSS: ",_time)44 epoch=convertTimeToEpoch_v2(_time)45 else:46 print("unusable time format!!")47 sys.exit(1)48 return epoch49# YYYY-mm-dd HH:MM:SS -> epoch50def convertTimeToEpoch(_time):51 date_time = "%s.%s.%s %s:%s:%s" %(_time[8:10], _time[5:7], _time[:4], _time[11:13], _time[14:16], _time[17:19])52 pattern = "%d.%m.%Y %H:%M:%S"53 epoch = int (time.mktime(time.strptime(date_time, pattern)))54 return epoch55# YYYYmmddHHMMSS -> dd.mm.YY HH:MM:SS56def convertTimeToEpoch_v2(_time):57 _time=str(_time)58 date_time = "%s.%s.%s %s:%s:%s" %(_time[6:8], _time[4:6], _time[:4], _time[8:10], _time[10:12], _time[12:])59 pattern = "%d.%m.%Y %H:%M:%S"60 epoch = int (time.mktime(time.strptime(date_time, pattern)))61 return epoch62# YYYY-MM-DD HH:MM:SS.SSS ->epoch63def convertMilliTimeToEpoch(_time):64 date_time = "%s.%s.%s %s:%s:%s.%s" %(_time[8:10], _time[5:7], _time[:4], _time[11:13], _time[14:16], _time[17:19],_time[20:23])65 pattern = "%d.%m.%Y %H:%M:%S.%f"66 dt=datetime.strptime(date_time,pattern)67 _ut = datetime.utcfromtimestamp(0)68 delta=dt-_ut69 epoch=int(delta.total_seconds() * 1000)70 return epoch71# YYYY-MM-DDTHH:MM:SS.SSS ->epoch72def convertMilliTimeToEpoch_v2(_time):73 date_time = "%s.%s.%s %s:%s:%s,%s" %(_time[8:10], _time[5:7], _time[:4], _time[11:13], _time[14:16], _time[17:19],_time[20:23])74 pattern = "%d.%m.%Y %H:%M:%S,%f"75 dt=datetime.strptime(date_time,pattern)76 _ut = datetime.utcfromtimestamp(0)77 delta = dt - _ut78 epoch = int(delta.total_seconds() * 1000)79 return epoch80def file2df(_filename, _field, _ts, _carid):81 82 f_extension = os.path.splitext(_filename)[1]83 col=_field+[_ts,_carid]84 print85 if f_extension == '.csv' or f_extension == '.CSV':86 try:87 chunks = pd.read_csv(_filename, usecols = col ,low_memory=False, chunksize=10000, encoding='utf-8')88 except UnicodeDecodeError:89 try:90 chunks = pd.read_csv(_filename,usecols = col, low_memory=False, chunksize=10000, encoding='euc-kr')91 except UnicodeDecodeError:92 chunks = pd.read_csv(_filename, usecols = col, low_memory=False, chunksize=10000, encoding='cp949')93 94 df = pd.concat(chunks, ignore_index=True)95 96 elif f_extension == '.xlsx' or f_extension == '.XLSX':97 df = pd.read_excel(_filename, usecols = col, converters={ts:str})98 else:99 df = []100 _tmp=(", ".join(_field))101 print("\n\n****[Covert File: %s to Dataframe]****" %_filename)102 print(" File: %s\n Field name: %s\n DataFrame length: %d" %(_filename,_tmp,len(df)))103 print("************************************************************")104 return df105def pack_to_meta(field, ts, carid, metric, pn, cn, ip,port):106 ret = {}107 ret['field']=field.split('|')108 ret['timestamp']=ts109 ret['carid']=carid110 ret['metric']=metric111 ret['pn']= pn112 ret['cn']= cn113 ret['url']='http://'+ip+':'+port+str('/api/put')114 return ret115def recursive_search_dir(_nowDir, _filelist):116 dir_list = [] # íì¬ ëë í 리ì ìë¸ëë í ë¦¬ê° ë´ê¸¸ list117 f_list = os.listdir(_nowDir)118 print(" [loop] recursive searching ", _nowDir)119 for fname in f_list:120 file_extension = os.path.splitext(fname)[1]121 # print(file_extension)122 if file_extension == '.csv' or file_extension == '.CSV' : # csv123 _idx = -4124 elif file_extension == '.xlsx' or file_extension == '.XLSX' : # excel125 _idx = -5126 else: pass127 if os.path.isdir(_nowDir+'/'+fname):128 dir_list.append(_nowDir+'/'+fname)129 elif os.path.isfile(_nowDir+'/'+fname):130 if fname[_idx:] == file_extension:131 _filelist.append(_nowDir+'/'+fname)132 for toDir in dir_list:133 recursive_search_dir(toDir, _filelist)134def brush_args():135 _len = len(sys.argv)136 if _len < 9:137 print(" ì¶ê° ì 보를 ì
ë ¥í´ ì£¼ì¸ì. ì usage ì¤ëª
ì ì°¸ê³ í´ ì£¼ììì¤")138 print(" python ì¤ííì¼ì í¬í¨íì¬ ìê·ë¨¼í¸ ê°¯ì 9ê° íì ")139 print(" íì¬ ìê·ë¨¼í¸ %s ê°ê° ì
ë ¥ëììµëë¤." % (_len))140 print(" check *this_run.sh* file ")141 exit(" You need to input more arguments, please try again \n")142 _field = sys.argv[1]143 _ts = sys.argv[2]144 _carid = sys.argv[3]145 _metric = sys.argv[4]146 _pn = int(sys.argv[5])147 _cn = int(sys.argv[6])148 _ip = sys.argv[7]149 _port = sys.argv[8]150 return _field, _ts,_carid, _metric,_pn,_cn,_ip,_port151if __name__ == "__main__":152 field,ts,carid,metric,pn,cn,ip,port=brush_args()153 file_dir='../files'154 file_list=[]155 recursive_search_dir(file_dir, file_list)156 print("\n--------------------file list--------------------")157 for f in file_list:158 _size=os.path.getsize(f)/(1024.0*1024.0)159 print("file: %s size: %.3f (MB)" %(f,_size))160 #print(os.path.splitext(f)[1])161 print("\n--------------------------------------------------\n")162 meta = pack_to_meta(field, ts, carid, metric, pn, cn, ip, port)163 # ìë¸ íë¡ì¸ì¤ ê´ë¦¬ì, ìì°ì, ìë¹ì ìì±164 workers = pcs.Workers(pn, cn)165 works_basket_list = workers.start_work(meta)166 start_time=time.time()167 for file_name in file_list:168 # files -> df169 df= file2df(file_name, meta['field'], ts, carid)170 if len(df) == 0:171 continue172 173 elif len(df) < meta['pn']:174 for idx in range(pn):175 while (works_basket_list[idx].full()):176 time.sleep(0.5)177 if idx == 0:178 works_basket_list[idx].put(df)179 else:180 works_basket_list[idx].put('None')181 start=0182 end=start+len(df)//pn183 for idx in range(pn):184 if idx == pn-1:185 end = len(df)186 while (works_basket_list[idx].full()):187 time.sleep(0.5)188 works_basket_list[idx].put(df[start:end])189 start = end190 end = start+len(df)//pn191 print("\nmain : [files -> df] done")192 print("work basketì 모ë data ì ì¡ ìë£")193 print("subprocessê° ìì§ ì¤í ì¤ ì
ëë¤...\n")194 lines = workers.report()195 totallines=0196 for line in lines:197 totallines += line198 end_time = time.time()199 print("total run time : %f" %(end_time-start_time))...
targetbigintbenchmark.py
Source:targetbigintbenchmark.py
1#! /usr/bin/env python2import sys3from time import time4from rpython.rlib.rbigint import rbigint5# __________ Entry point __________6def entry_point(argv):7 """8 All benchmarks are run using --opt=2 and minimark gc (default).9 10 Benchmark changes:11 2**N is a VERY heavy operation in default pypy, default to 10 million instead of 500,000 used like an hour to finish.12 13 A cutout with some benchmarks.14 Pypy default:15 mod by 2: 7.97818116 mod by 10000: 4.01612117 mod by 1024 (power of two): 3.96643918 Div huge number by 2**128: 2.90682119 rshift: 2.44458920 lshift: 2.50074621 Floordiv by 2: 4.43113422 Floordiv by 3 (not power of two): 4.40439623 2**500000: 23.20672424 (2**N)**5000000 (power of two): 13.88611825 10000 ** BIGNUM % 100 8.46437826 i = i * i: 10.12150527 n**10000 (not power of two): 16.29698928 Power of two ** power of two: 2.22412529 v = v * power of two 12.22839130 v = v * v 17.11993331 v = v + v 6.48995732 Sum: 142.68654733 34 Pypy with improvements:35 mod by 2: 0.00705936 mod by 10000: 3.20429537 mod by 1024 (power of two): 0.00940138 Div huge number by 2**128: 1.36851139 rshift: 2.34529540 lshift: 1.33976141 Floordiv by 2: 1.53202842 Floordiv by 3 (not power of two): 4.00560743 2**500000: 0.03346644 (2**N)**5000000 (power of two): 0.04709345 10000 ** BIGNUM % 100 1.20731046 i = i * i: 3.99816147 n**10000 (not power of two): 6.32325048 Power of two ** power of two: 0.01325849 v = v * power of two 3.56745950 v = v * v 6.31668351 v = v + v 2.75730852 Sum: 38.07594653 # Notice: This is slightly old!54 With SUPPORT_INT128 set to False55 mod by 2: 0.00410356 mod by 10000: 3.23743457 mod by 1024 (power of two): 0.01636358 Div huge number by 2**128: 2.83623759 rshift: 2.34386060 lshift: 1.17266561 Floordiv by 2: 1.53747462 Floordiv by 3 (not power of two): 3.79601563 2**500000: 0.32726964 (2**N)**5000000 (power of two): 0.08470965 10000 ** BIGNUM % 100 2.06321566 i = i * i: 8.10963467 n**10000 (not power of two): 11.24329268 Power of two ** power of two: 0.07255969 v = v * power of two 9.75353270 v = v * v 13.56984171 v = v + v 5.76046672 Sum: 65.92866773 """74 sumTime = 0.075 V2 = rbigint.fromint(2)76 num = rbigint.pow(rbigint.fromint(100000000), rbigint.fromint(1024))77 t = time()78 for n in xrange(600000):79 rbigint.mod(num, V2)80 81 _time = time() - t82 sumTime += _time83 print "mod by 2: ", _time84 85 by = rbigint.fromint(10000)86 t = time()87 for n in xrange(300000):88 rbigint.mod(num, by)89 90 _time = time() - t91 sumTime += _time92 print "mod by 10000: ", _time93 94 V1024 = rbigint.fromint(1024)95 t = time()96 for n in xrange(300000):97 rbigint.mod(num, V1024)98 99 _time = time() - t100 sumTime += _time101 print "mod by 1024 (power of two): ", _time102 103 t = time()104 num = rbigint.pow(rbigint.fromint(100000000), rbigint.fromint(1024))105 by = rbigint.pow(rbigint.fromint(2), rbigint.fromint(128))106 for n in xrange(80000):107 rbigint.divmod(num, by)108 109 _time = time() - t110 sumTime += _time111 print "Div huge number by 2**128:", _time112 113 t = time()114 num = rbigint.fromint(1000000000)115 for n in xrange(160000000):116 rbigint.rshift(num, 16)117 118 _time = time() - t119 sumTime += _time120 print "rshift:", _time121 122 t = time()123 num = rbigint.fromint(1000000000)124 for n in xrange(160000000):125 rbigint.lshift(num, 4)126 127 _time = time() - t128 sumTime += _time129 print "lshift:", _time130 131 t = time()132 num = rbigint.fromint(100000000)133 for n in xrange(80000000):134 rbigint.floordiv(num, V2)135 136 _time = time() - t137 sumTime += _time138 print "Floordiv by 2:", _time139 140 t = time()141 num = rbigint.fromint(100000000)142 V3 = rbigint.fromint(3)143 for n in xrange(80000000):144 rbigint.floordiv(num, V3)145 146 _time = time() - t147 sumTime += _time148 print "Floordiv by 3 (not power of two):",_time149 150 t = time()151 num = rbigint.fromint(500000)152 for n in xrange(10000):153 rbigint.pow(V2, num)154 155 _time = time() - t156 sumTime += _time157 print "2**500000:",_time158 t = time()159 num = rbigint.fromint(5000000)160 for n in xrange(31):161 rbigint.pow(rbigint.pow(V2, rbigint.fromint(n)), num)162 163 _time = time() - t164 sumTime += _time165 print "(2**N)**5000000 (power of two):",_time166 167 t = time()168 num = rbigint.pow(rbigint.fromint(10000), rbigint.fromint(2 ** 8))169 P10_4 = rbigint.fromint(10**4)170 V100 = rbigint.fromint(100)171 for n in xrange(60000):172 rbigint.pow(P10_4, num, V100)173 174 _time = time() - t175 sumTime += _time176 print "10000 ** BIGNUM % 100", _time177 178 t = time()179 i = rbigint.fromint(2**31)180 i2 = rbigint.fromint(2**31)181 for n in xrange(75000):182 i = i.mul(i2)183 _time = time() - t184 sumTime += _time185 print "i = i * i:", _time186 187 t = time()188 189 for n in xrange(10000):190 rbigint.pow(rbigint.fromint(n), P10_4)191 192 _time = time() - t193 sumTime += _time194 print "n**10000 (not power of two):",_time195 196 t = time()197 for n in xrange(100000):198 rbigint.pow(V1024, V1024)199 200 _time = time() - t201 sumTime += _time202 print "Power of two ** power of two:", _time203 204 205 t = time()206 v = rbigint.fromint(2)207 P62 = rbigint.fromint(2**62)208 for n in xrange(50000):209 v = v.mul(P62)210 211 _time = time() - t212 sumTime += _time213 print "v = v * power of two", _time214 215 t = time()216 v2 = rbigint.fromint(2**8)217 for n in xrange(28):218 v2 = v2.mul(v2)219 220 _time = time() - t221 sumTime += _time222 print "v = v * v", _time223 224 t = time()225 v3 = rbigint.fromint(2**62)226 for n in xrange(500000):227 v3 = v3.add(v3)228 229 _time = time() - t230 sumTime += _time231 print "v = v + v", _time232 233 print "Sum: ", sumTime234 235 return 0236# _____ Define and setup target ___237def target(*args):238 return entry_point, None239if __name__ == '__main__':240 res = entry_point(sys.argv)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!