Skip to content

Instantly share code, notes, and snippets.

@stuppie
Created May 4, 2017 22:21
Show Gist options
  • Save stuppie/e523bf617416e1490c25464d5a485396 to your computer and use it in GitHub Desktop.
Save stuppie/e523bf617416e1490c25464d5a485396 to your computer and use it in GitHub Desktop.
Benchmarking Wikidata sparql query results
$ /usr/bin/time -v python3 requests_text.py 1
Command being timed: "python3 requests_text.py 1"
User time (seconds): 0.15
System time (seconds): 0.02
Percent of CPU this job got: 11%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.60
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 39160
$ /usr/bin/time -v python3 requests_text.py 2
Command being timed: "python3 requests_text.py 2"
User time (seconds): 16.94
System time (seconds): 0.06
Percent of CPU this job got: 95%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:17.87
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 287756
import json
import requests
import sys
endpoint = 'https://query.wikidata.org/sparql'
query = """
SELECT ?p ?label WHERE {
?p p:P686/ps:P686 ?zz .
OPTIONAL { ?p skos:altLabel ?label FILTER (lang(?label) = "en") . }
} LIMIT 9999
"""
query2 = query + "\n # bla"
headers = {
'Accept': 'application/sparql-results+json',
'User-Agent': 'wikidataintegrator: github.com/SuLab/WikidataIntegrator'
}
if __name__ == "__main__":
if sys.argv[1] == '1':
#print(query)
params = {'query': query, 'format': 'json'}
response = requests.get(endpoint, params=params, headers=headers)
response.encoding = 'utf8'
d = json.loads(response.text)
else:
#print(query2)
params = {'query': query2, 'format': 'json'}
response = requests.get(endpoint, params=params, headers=headers)
d = json.loads(response.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment