Skip to content

Instantly share code, notes, and snippets.

@anatoly-scherbakov
Last active February 17, 2022 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anatoly-scherbakov/6deac9b7540ecacc723603d83d2d9cee to your computer and use it in GitHub Desktop.
Save anatoly-scherbakov/6deac9b7540ecacc723603d83d2d9cee to your computer and use it in GitHub Desktop.
OWL RL & RDFLib profiling
import cProfile
import sys
from pstats import SortKey, Stats
import owlrl
from owlrl import OWLRL_Extension
import rdflib
def test_profile_owlrl():
print(f'Python: {sys.version}')
print(f'RDFLib: {rdflib.__version__}')
print(f'OWL RL: {owlrl.__version__}')
graph = rdflib.Graph().parse(
'https://schema.org/version/latest/schemaorg-current-https.jsonld',
format='json-ld',
)
with cProfile.Profile() as profiler:
owlrl.DeductiveClosure(OWLRL_Extension).expand(graph)
Stats(profiler).strip_dirs().sort_stats(SortKey.TIME).print_stats(10)
if __name__ == '__main__':
test_profile_owlrl()
@anatoly-scherbakov
Copy link
Author

anatoly-scherbakov commented Feb 17, 2022

Output

Python: 3.8.1 (default, Feb 21 2020, 23:12:01) 
[GCC 9.2.1 20191008]
RDFLib: 6.1.1
OWL RL: 6.0.2
         202428907 function calls in 108.534 seconds

   Ordered by: internal time
   List reduced from 95 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  8510246   14.562    0.000   26.914    0.000 __init__.py:216(__contains__)
  8510246   11.345    0.000   62.434    0.000 __init__.py:190(__getitem__)
  8510246    6.770    0.000    6.770    0.000 term.py:80(_is_valid_uri)
 10408478    6.323    0.000    6.323    0.000 term.py:144(__eq__)
  4223629    6.081    0.000   18.259    0.000 memory.py:305(triples)
 17020492    5.811    0.000    7.193    0.000 __init__.py:223(<genexpr>)
  8510246    5.460    0.000   19.849    0.000 __init__.py:116(term)
  8510246    4.913    0.000   13.738    0.000 term.py:233(__new__)
  8510244    3.956    0.000   66.390    0.000 __init__.py:204(__getattr__)
  4223629    3.373    0.000   22.011    0.000 graph.py:453(triples)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment