Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving unit database as JSON file #7

Open
jonlym opened this issue Jan 6, 2020 · 3 comments
Open

Saving unit database as JSON file #7

jonlym opened this issue Jan 6, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@jonlym
Copy link
Member

jonlym commented Jan 6, 2020

Currently, VUnits stores the unit database in its code, which is imported whenever the vunits.db module is accessed. However, prefixes and suffixes are added during the import process, which can slow down the initialization of the database.

One option is to save the database as a JSON file, which will probably load faster and can be updated whenever necessary.

@jonlym jonlym added the enhancement New feature or request label Jan 6, 2020
@jonlym jonlym changed the title Saving unit database as pickle file Saving unit database as JSON file Jan 6, 2020
@jonlym
Copy link
Member Author

jonlym commented Jan 6, 2020

The following code was run using the old approach and the new approach.

import timeit

'''Code to evaluate'''
code1 = r"""
from vunits.db import unit_db
unit_db['kg']"""


'''Evaluate performance'''
print('Time: {}'.format(min(timeit.repeat(code1, repeat=10))))

The times obtained are as follows.

Approach Time
Initializing DB when imported (Old Method) 0.892
Loading from JSON file (New Method) 0.711

The new approach shows some speedup but not as significant as I would like. For now, we'll implement the new approach but will still look for more ways to speed up the database initialization process further.

@jonlym
Copy link
Member Author

jonlym commented Jan 7, 2020

Fixed in commit 98c8304

@jonlym jonlym closed this as completed Jan 7, 2020
@jonlym
Copy link
Member Author

jonlym commented Jun 29, 2020

Changed Quantity objects to use dictionaries instead of Dataframes in commit 01fcfcf. Reduced IO time of above script to 0.5050562999999997.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant