예제 #1
0
 def wrapper(*args, **kwargs):
     for i in range(repeat):
         start = time.perf_counter()
         for _ in range(number):
             func(*args, **kwargs)
         elapsed = (time.perf_counter() - start)
         print('Time of {} used: {} '.format(i, elapsed))
예제 #2
0
 async def ping(self, ctx):
     t1 = time.perf_counter()
     async with ctx.typing():
         pass
     t2 = time.perf_counter()
     await ctx.send(":ping_pong: Pong! It took {}ms".format(
         round((t2 - t1) * 1000)))
예제 #3
0
 def inner(*args, **kwargs):
     print(func.__name__, end=" ... ")
     acc = float("inf")
     for i in range(n_iter):
         tick = time.perf_counter()
         result = func(*args, **kwargs)
         cc = min(acc, time.perf_counter() - tick)
         print(acc)
         return result
예제 #4
0
def detectorDirector():
    # Reddit Detector
    startTime = time.perf_counter()
    prettyPrint(bcolors.OKBLUE,
                "Checking reddit sources and downloading any new content")
    redditThreads = []
    for source in redditSources:
        t = threading.Thread(target=reddit_detector,
                             args=(datetime.utcnow(), source))
        redditThreads.append(t)
        t.start()
    prettyPrint(bcolors.OKBLUE,
                "All threads finished, closing all active processes")
    for threads in redditThreads:
        threads.join()
    # A little alert to let the user know the function is over and how long it took
    endTime = time.perf_counter()
    prettyPrint(
        bcolors.OKGREEN,
        f"Reddit sources checked and new content downloaded. Process took {endTime - startTime:0.4f} seconds"
    )
예제 #5
0
def main():
    sites = [
        'https://en.wikipedia.org/wiki/Portal:Arts',
        'https://en.wikipedia.org/wiki/Portal:History',
        'https://en.wikipedia.org/wiki/Portal:Society',
        'https://en.wikipedia.org/wiki/Portal:Biography',
        'https://en.wikipedia.org/wiki/Portal:Mathematics',
        'https://en.wikipedia.org/wiki/Portal:Technology',
        'https://en.wikipedia.org/wiki/Portal:Geography',
        'https://en.wikipedia.org/wiki/Portal:Science',
        'https://en.wikipedia.org/wiki/Computer_science',
        'https://en.wikipedia.org/wiki/Python_(programming_language)',
        'https://en.wikipedia.org/wiki/Java_(programming_language)',
        'https://en.wikipedia.org/wiki/PHP',
        'https://en.wikipedia.org/wiki/Node.js',
        'https://en.wikipedia.org/wiki/The_C_Programming_Language',
        'https://en.wikipedia.org/wiki/Go_(programming_language)'
    ]

    start_time = time.perf_counter()
    asyncio.run(download_all(sites))
    end_time = time.perf_counter()
    print('Download {} sites in {} seconds'.format(len(sites), end_time - start_time))
Lokalna data: 12/07/20

Lokalny czas: 13:53:13

Czas obecny: 01:55:02 PM

24-godz. czas: 13:57

"""
>>>
>>> import time
>>> import sys
>>> print(sys.version)
3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
>>>
>>> print(time.perf_counter(), time.localtime(time.perf_counter()))
89.4915672 time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=1, tm_min=1, tm_sec=29, tm_wday=3, tm_yday=1, tm_isdst=0)
>>> 

>>> import time
>>> time.time()
1614326427.3598132
>>> time.localtime(time.time())
time.struct_time(tm_year=2021, tm_mon=2, tm_mday=26, tm_hour=9, tm_min=0, tm_sec=57, tm_wday=4, tm_yday=57, tm_isdst=0)
>>> time.asctime(time.localtime(time.time()))
'Fri Feb 26 09:01:38 2021'
>>> time.localtime(time.clock())
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    time.localtime(time.clock())
AttributeError: module 'time' has no attribute 'clock'
예제 #7
0
### Final project

from datetime import time

from pyspark.sql.functions import col, asc, concat_ws
from pyspark.sql import SparkSession
import pyspark
import re
import time
start = time.perf_counter()
# spark = SparkSession.builder.master("local[*]").appName("Yelp EDA").getOrCreate()
from pyspark.context import SparkContext
from pyspark.serializers import MarshalSerializer
# from pyspark.serializers import  PickleSerializer
sc = SparkContext("local", "serialization app", serializer=MarshalSerializer())
spark = SparkSession(sc)
spark.sparkContext.setLogLevel("ERROR")

path_from_home = "C://Users/junaz/OneDrive/Desktop/Spark/yelp/"
# reviews.parquet sample_review
user_review_path = path_from_home + "reviews.parquet"

reviews = spark.read.parquet(user_review_path)

# reviews.select(reviews.stars,reviews.text).toPandas().to_json(path_from_home+"sample_review")
business_path = path_from_home + "business.parquet"

business = spark.read.parquet(business_path)

print(reviews.show(5))
def getTime():
    """
    devuelve el instante tiempo de procesamiento en milisegundos
    """
    return float(time.perf_counter() * 1000)