ok
This commit is contained in:
@@ -66,14 +66,16 @@ def create_tables_postgres():
|
||||
try:
|
||||
with connect_postgres() as conn:
|
||||
with conn.cursor() as cursor:
|
||||
start_time = time.time()
|
||||
for command in sql_command_create_table:
|
||||
cursor.execute(command)
|
||||
conn.commit()
|
||||
end_time = time.time()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
except (psycopg2.DatabaseError, Exception) as error:
|
||||
print(error)
|
||||
|
||||
return end_time-start_time
|
||||
|
||||
def create_data_postgres():
|
||||
sql_command_copy =(
|
||||
@@ -83,14 +85,16 @@ def create_data_postgres():
|
||||
try:
|
||||
with connect_postgres() as conn:
|
||||
with conn.cursor() as cursor:
|
||||
start_time = time.time()
|
||||
for command in sql_command_copy:
|
||||
cursor.execute(command)
|
||||
conn.commit()
|
||||
end_time = time.time()
|
||||
cursor.close()
|
||||
conn.close()
|
||||
except (psycopg2.DatabaseError, Exception) as error:
|
||||
print(error)
|
||||
|
||||
return end_time - start_time
|
||||
|
||||
def requete_postgres(str):
|
||||
try:
|
||||
@@ -99,12 +103,12 @@ def requete_postgres(str):
|
||||
start = time.time()
|
||||
cursor.execute(str)
|
||||
conn.commit()
|
||||
temps = time.time() -start
|
||||
print("Cette requête prends:", temps, "seconde")
|
||||
end = time.time() -start
|
||||
cursor.close()
|
||||
conn.close()
|
||||
except (psycopg2.DatabaseError, Exception) as error:
|
||||
print(error)
|
||||
return end-start
|
||||
|
||||
def reset_database_postgres():
|
||||
try:
|
||||
|
||||
24
main.py
24
main.py
@@ -2,8 +2,6 @@ from MonetDB import *
|
||||
from PostgreSQL import *
|
||||
import time
|
||||
|
||||
data =[]
|
||||
header=["Nom de requete","Temps"]
|
||||
#Monet DB
|
||||
requeteSelect1MonetDB = """SELECT * FROM flights WHERE "AIRLINE" = 'AA';"""
|
||||
requeteSelect2MonetDB = """SELECT * FROM flights;"""
|
||||
@@ -27,17 +25,6 @@ requeteDeletePostgreSQL = """DELETE FROM flights WHERE "DAY" > 10"""
|
||||
requeteInsertPostgreSQL = """INSERT INTO flights SELECT * FROM flights10"""
|
||||
requeteDropflight10MonetSQL = """DROP TABLE flights10"""
|
||||
|
||||
def display_table(data, headers):
|
||||
column_lengths = [len(header) for header in headers]
|
||||
for row in data:
|
||||
for idx, cell in enumerate(row):
|
||||
column_lengths[idx] = max(column_lengths[idx], len(str(cell)))
|
||||
row_format = " | ".join(["{{:<{}}}".format(length) for length in column_lengths])
|
||||
print(row_format.format(*headers))
|
||||
print("-|-".join(['-' * length for length in column_lengths]))
|
||||
for row in data:
|
||||
print(row_format.format(*[str(cell) for cell in row])) # Ensure cells are strings
|
||||
|
||||
def initMonetDB():
|
||||
reset_data_monetdb()
|
||||
time = create_table_monetdb()
|
||||
@@ -69,8 +56,6 @@ def execForMonetDB(n, tabReq):
|
||||
t[j] = t[j]/n
|
||||
print("[MonetDB] requete (moyenne de",n,") :", tabReq[j] , "\n time = ", t[j], "s\n")
|
||||
|
||||
|
||||
|
||||
def initPostgreSQL():
|
||||
reset_database_postgres()
|
||||
start_time = time.time()
|
||||
@@ -107,18 +92,11 @@ def execForPostgreSQL(n, tabReq):
|
||||
t[j] = t[j] / n
|
||||
print("[PostgreSQL] requete (moyenne de", n, ") :", tabReq[j], "\n time = ", t[j], "s\n")
|
||||
|
||||
def runPostgreSQL():
|
||||
data.append([requeteSelect1PostgreSQL,execPostgreSQL(requeteSelect1PostgreSQL)])
|
||||
data.append([requeteSelect2PostgreSQL,execPostgreSQL(requeteSelect2PostgreSQL)])
|
||||
data.append([requeteSelect3PostgreSQL,execPostgreSQL(requeteSelect3PostgreSQL)])
|
||||
data.append([requeteSelect4PostgreSQL,execPostgreSQL(requeteSelect4PostgreSQL)])
|
||||
|
||||
if __name__ == '__main__':
|
||||
initMonetDB()
|
||||
runMonetDB()
|
||||
|
||||
#initPostgreSQL()
|
||||
|
||||
runPostgreSQL()
|
||||
display_table(data, header)
|
||||
#runPostgreSQL()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user