DigitalMag

Benchmarks on Count Agregate for big data

May 6th, 2020
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # -*- coding: utf- 8 -*-
  2. # Python 2.X
  3.  
  4.  
  5. import time
  6. import psycopg2
  7.  
  8. con = psycopg2.connect(
  9.   database="test",
  10.   user="postgres",
  11.   password="",
  12.   host="127.0.0.1",
  13.   port="5432"
  14. )
  15.  
  16. cur = con.cursor()
  17.  
  18. cur.execute('''CREATE TABLE IF NOT EXISTS test
  19.     (id SERIAL PRIMARY KEY NOT NULL,
  20.     name TEXT NOT NULL,
  21.     age INT NOT NULL,
  22.     department CHAR(50));''')
  23.  
  24.  
  25. a = time.clock()
  26.  
  27.  
  28. # for i in range(1000000): cur.execute("INSERT INTO test (name,age,department) VALUES ('John', 18, 'ICT')")
  29. # con.commit()
  30.  
  31. ##cur.execute("SELECT name, age, department FROM test WHERE id=300000"); rows = cur.fetchall()
  32. ##cur.execute("SELECT name, age, department FROM test WHERE id<30"); rows = cur.fetchall()
  33. cur.execute("SELECT COUNT(*) FROM test WHERE id<100000 GROUP BY age"); rows = cur.fetchall()
  34. ##cur.execute("show data_directory;"); rows = cur.fetchall()
  35.  
  36. print time.clock() - a
  37.  
  38. for u in rows: print u[0]
  39.  
  40.  
  41. '''
  42. 1 mln notes ~= 100-120 mb/ Count
  43. speed for select for table^1000 notes ~= 3ms
  44. speed for select for table^1000000 notes ~= 100ms
  45. '''
  46.  
  47.  
  48. con.close()
  49.  
  50. print('ok')
Add Comment
Please, Sign In to add comment