Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to use visualize_runtimes

import threading
import multiprocessing
import math
import numpy as np
import time
import matplotlib.pyplot as plt
import glob
from PIL import Image
import random
from random import sample
import string
from concurrent.futures import ThreadPoolExecutor


cpu_workers = 3
nSim = 12

def generate_bar_colors(cpu_workers):
    colors = ['red', 'gold', 'royalblue']
    return colors

def visualize_runtimes(results, title):
    colors = generate_bar_colors(cpu_workers)
    plt.rcParams["font.family"] = "Times New Roman"
    plt.rcParams['axes.axisbelow'] = True
    start,stop = np.array(results).T
    plt.barh(range(len(start)),stop-start,left=start, color=colors)
    plt.grid(axis='x', color= 'lightgrey')
    plt.title("Tasks", rotation='horizontal', fontsize=12, horizontalalignment="left", x=0)
    plt.xlabel("Seconds", fontsize=12, horizontalalignment='right', x=1.0)

def multithreading(func, args, workers):
    begin_time=time.time()
    with ThreadPoolExecutor(max_workers = workers) as executor:
        res = executor.map(func, args, [begin_time for i in range (len(args))])
    return list(res)

def simulation(i, base):
    start = time.time() - base
    print(str(threading.current_thread().getName()) + ': '+ str(i))
    time.sleep(math.cos(i)+i*0.1+1)
    stop = time.time() - base
    return start, stop


if __name__ == '__main__':
    visualize_runtimes(multithreading(simulation, i, cpu_workers), "Multi-threading")
    plt.savefig('foo.png', bbox_inches='tight')

plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: py to flag converter online 
Python :: File "main.py", line 21 print("total harga:idr", bakso bulat +str Minuman Drink): ^ SyntaxError: invalid syntax 
Python :: code error correction 
Python :: how to make a ip tracker in python 
Python :: gnuplot sum over a column 
Python :: draw a bow tie in python 
Python :: light fm cold start problem 
Python :: wxpython menu callback stackoverflow 
Python :: python copy formula ghseets 
Python :: iterate over meta tag python 
Python :: sphinx, where to write the glossary of a sofware project 
Python :: python regex words with apostrophe in middle 
Shell :: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation 
Shell :: Error: You must install at least one postgresql-client-<version package 
Shell :: check nginx status 
Shell :: postgres status ubuntu 
Shell :: how to do compress video in linux 
Shell :: git name email 
Shell :: how to remove unnecessary packages in linux 
Shell :: how can I find perticular extension in ubuntu? 
Shell :: linux check ram frequency 
Shell :: pip check for updates 
Shell :: sudo: aptitude: command not found 
Shell :: flask restful install 
Shell :: ubuntu command ram info 
Shell :: brew reinstall mysql 
Shell :: install rclone 
Shell :: install ufw centos 
Shell :: magento 2 version file permissions 
Shell :: MaatwebsiteExcelExcel not found 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =