def main(): n = 10 for i in range(3,7): N = n**i res = open('primes_' + str(N) + '.txt','w') g = genPrimes() timing.log('Generating first ' + str(N) + ' primes:') start = timing.clock() for i in range(N): res.write(str(next(g)) + '\n') end = timing.clock() print ('Time elapsed: ', timing.secondsToStr(end-start)) print ('\n')
def write_info_file(matches): """! Function writes Info File, from info_dict The Info File contains information regarding the design, such as amount of words found, amount of subcircuits found, timing information and results. It can easily be copied to excel, allowing for simple comparison. @param [in] constants as dictionary of constants @param [in] matches as list of subcurcuit matches @param [out] info_file is written to disk """ print_info("Writing info file") # open info file infoFile = open("outputFiles/infoDump/" + design_name + str(datetime.now().replace(microsecond=0)) + ".txt", 'w+') # write general info to File infoFile.write('Date; ' + str(date.today()) + "\n") infoFile.write('design_name; ' + design_name + "\n") infoFile.write("\n") infoFile.write("Constants\n") infoFile.write("Cut Size;" + str(constants["cutSize"]) + "\n") infoFile.write("Shape Size;" + str(constants["shapeSize"]) + "\n") infoFile.write("Allowed Word Size;" + str(constants["wordLenght"]) + "\n") infoFile.write("partWords;" + str(constants["partWord"]) + "\n") infoFile.write("Word Distance;" + str(constants["wordDistance"]) + "\n") infoFile.write("Search Depth;" + str(constants["searchDepth"]) + "\n") infoFile.write("Do word id?;" + str(info_dict["process_word"]) + "\n") infoFile.write("Do data_path?;" + str(info_dict["process_data"]) + "\n") infoFile.write("Do find subcircuits?;" + str(info_dict["process_subc"]) + "\n") infoFile.write("Do id circuits?;" + str(info_dict["process_cirid"]) + "\n") # write Timing info to file infoFile.write("\n") infoFile.write("Timing;" + timing.secondsToStr(info_dict["elapsed"]) + "\n") infoFile.write("Parsing;" + timing.secondsToStr(info_dict["elapsedPars"]) + "\n") infoFile.write("WordID Total;" + timing.secondsToStr(info_dict["elapsedword_id"]) + "\n") infoFile.write(" Cut ID;" + timing.secondsToStr(info_dict["elapsedCutFind"]) + "\n") infoFile.write(" Words from Cut;" + timing.secondsToStr(info_dict["elapsedCutWords"]) + "\n") infoFile.write(" Shape ID & Words from Shape;" + timing.secondsToStr(info_dict["elapsedShape"]) + "\n") infoFile.write(" Word Check;" + timing.secondsToStr(info_dict["elapsedCheckWord"]) + "\n") infoFile.write("\n") infoFile.write("WordProp Total;" + timing.secondsToStr(info_dict["elapseddata_path"]) + "\n") infoFile.write(" data calc;" + timing.secondsToStr(info_dict["elapsedDataPath"]) + "\n") infoFile.write(" data path cleaning;" + timing.secondsToStr(info_dict["elapsedClean"]) + "\n") infoFile.write(" data path drawring;" + timing.secondsToStr(info_dict["elapsedDraw"]) + "\n") infoFile.write("\n") infoFile.write("Subcircuit ID Total;" + timing.secondsToStr(info_dict["elapsedsubID"]) + "\n") infoFile.write(" finding Boundary words;" + timing.secondsToStr(info_dict["elapsedBound"]) + "\n") infoFile.write(" finding subcircuits;" + timing.secondsToStr(info_dict["elapsedsubC"]) + "\n") infoFile.write(" checking subcircuits;" + timing.secondsToStr(info_dict["elapsedCheckSubC"]) + "\n") infoFile.write(" printing subcircuits;" + timing.secondsToStr(info_dict["elapsedPrint"]) + "\n") infoFile.write(" finding subcircuit functions;" + timing.secondsToStr(info_dict["elapsedFunc"]) + "\n") infoFile.write("Matching ;" + timing.secondsToStr(info_dict["elapsedMatch"]) + "\n") infoFile.write(" SAT;" + timing.secondsToStr(info_dict["elapsedSAT"]) + "\n") infoFile.write("\n") # write Stats to info infoFile.write("Stats\n") infoFile.write("Nr of gates;" + str(info_dict["gates"]) + "\n") infoFile.write("Average Nr of Cuts;" + str(info_dict["avrgCutLen"])+ "\n") infoFile.write("Max cuts for one Node;" + str(info_dict["maxCutLen"]) + "\n") infoFile.write("Nr of words found from Cut;" + str(info_dict["wordsCut"]) + "\n") infoFile.write("Size of pRep dictionary from file;" + str(info_dict["pRepDictLen"]) + "\n") infoFile.write("Nr of words found from bitslice;" + str(info_dict["bitsliceWords"]) + "\n") infoFile.write("Nr of words found from bitslice input;" + str(info_dict["inpsWordCut"]) + "\n") infoFile.write("Nr of words found from shape;" + str(info_dict["wordsShape"]) + "\n") infoFile.write("Unchecked source Words (without PIs/POs);" + str(info_dict["uncheckedWords"]) + "\n") infoFile.write("Checked source Words;" + str(info_dict["sourceWords"]) + "\n") infoFile.write("Chain words;" + str(info_dict["chainWords"]) + "\n") infoFile.write("Nr of control Wires;" + str(info_dict["control_wires"]) + "\n") infoFile.write("Nr of propergated Words;" + str(info_dict["propWords"]) + "\n") infoFile.write("Nr of candidate Words;" + str(info_dict["candWords"]) + "\n") infoFile.write("Lenght of DataPath;" + str(info_dict["dataPath"]) + "\n") infoFile.write("Nr of boundary word sets;" + str(info_dict["boundWords"]) + "\n") infoFile.write("Nr of checked subcircuits;" + str(info_dict["checkedCircuits"]) + "\n") # write Matches to info File infoFile.write("Nr of matches;" + str(len(matches)) + "\n") infoFile.write("Matches are; \n") for match in matches: infoFile.write("\t "+ str(match) + "\n") infoFile.write("Coverage of matches;" + str(info_dict["cov"]) + "\n") infoFile.write("\n") infoFile.write("subcircuit Info\n") for circuit in info_dict["circuits"]: infoFile.write(circuit + " contains " + str(info_dict["circuits"][circuit]) + " nodes. \n") matchList = [x.values() for x in matches if list(x.keys())[0] == circuit] if matchList: for match in matchList: infoFile.write(circuit + " is a match to " + str(list(match)[0]) + "\n") infoFile.write("\n") # close info file infoFile.close() return
arrayy = [1-15, 2-15, 'Fizz', 4-15, 'Buzz', 'Fizz', 7-15, 8-15, 'Fizz', 'Buzz', 11-15, 'Fizz', 13-15, 14-15, 'FizzBuzz'] # It' the list with the first 15 elements to be printed, just subtracting 15 from each number, because of the first iteration below for j in range(7): for i in range(len(arrayy)): if j*15+i>99 : return try: arrayy[i] += 15 print(arrayy[i]) except TypeError: # String + Number throws this error print(arrayy[i]) finally: print() ######################### # RUNNING ######################### import timing # With the import the time starts counting! firstTry() firstTryTime = timing.log("Finished First Try") secondTry() secondTryTime = timing.log("Finished Second Try", firstTryTime) ######################### # RESULTS ######################### print("Difference between First and Second Try") diff_1_2 = secondTryTime-firstTryTime print('Exact time: ', secondTryTime-firstTryTime) print('Rounded time: ', timing.secondsToStr(secondTryTime-firstTryTime))
save("level_counts_probabilities_list", cnt_prob_list_array) # calculating the compression ratio sizeBefore = flattenedImage.size * 8 print("Size before : " + str(sizeBefore) + " bits") sizeAfter = bs_length_counts + bs_length_levels + lvl_levels_list_array.size * 8 sizeAfter += cnt_prob_list_array.size * 64 + cnt_levels_list_array.size * 8 + lvl_prob_list_array.size * 64 print("Size After : " + str(sizeAfter) + " bits") compressionRatio = sizeBefore / sizeAfter print("compression ratio = " + str(compressionRatio)) # snap time at the end of encoding end_of_encoding_time = timing.snap() encoding_time = end_of_encoding_time - start_of_encoding_time timing.log("Encoding Time excluding time to take input from user", timing.secondsToStr(encoding_time)) # --------------------------------------------------------------------------------------------------------------------- # Inputs to the decoder # - Image size : number of Rows and number of Columns in the original image # - code table used to encode both the levels and the counts arrays # - The encoded Huffman binary strings for both the levels and the counts # - original image extension to write an image file after decoding # --------------------------------------------------------------------------------------------------------------------- # decoding # take a snap at start of decoding start_of_decoding_time = timing.snap() print("Start Decoding") decoded_levels = [] huff_decode(lvl_levels_list, lvl_prob_list, coded_levels_string, decoded_levels)