GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python-orm-benchmarks/benchmarks/trim.py at dev · objectbox/python-orm-benchmarks

Expand file tree

/

trim.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
35 lines (29 loc) · 1.23 KB
/

trim.py

Copy path

File metadata and controls

35 lines (29 loc) · 1.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
"""Untimed, after B and C: shrink the table back to the size D-K were designed for.
B and C insert BATCH_SIZE rows (default 10000) so their transactions measure insert throughput,
not mostly one durable commit. D-K run on the whole table, so this deletes the newest
BATCH_SIZE - ITERATIONS rows again: each of B and C leaves ITERATIONS rows, as before.
LARGE_TABLE=1 keeps all rows (D-K then run on ~2 x BATCH_SIZE rows). SQLite only; with
PostgreSQL/MySQL the rows stay. ObjectBox has its own objectbox/trim.py.
"""
import os
import sqlite3
import sys
def trim(table="journal"):
if os.environ.get("LARGE_TABLE", "0") != "0" or os.environ.get("DBTYPE", "sqlite") != "sqlite":
return
extra = int(os.environ.get("BATCH_SIZE", "10000")) - int(os.environ.get("ITERATIONS", "1000"))
if extra <= 0:
return
conn = sqlite3.connect("/tmp/db.sqlite3", timeout=60)
try:
with conn:
conn.execute(
f'DELETE FROM "{table}" WHERE rowid IN '
f'(SELECT rowid FROM "{table}" ORDER BY rowid DESC LIMIT ?)',
(extra,),
)
finally:
conn.close()
if __name__ == "__main__":
trim(*sys.argv[1:]) # Django: simple_journal<TEST>
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.