Comments (11)
Hi,
Last time I checked, isinstance was making ObjectPath significantly slower. If you do performance tests and the difference isn't so drastic nowadays, I'll accept your PR.
Best,
Adrian
from objectpath.
Oh, I did not realize the performance issue. If so, I think we should narrow down the issue to setData
method itself.
If we agree to support subclasses in objectpath, we could change this method using isinstance.
from objectpath.
concerning about the performance, here below is my testing results:
environment:
python2 version: 2.7.16
python3 version : 3.7.4
both installed via brew
Mac OS X version: 10.14.6 (18G103)
result: all in 10**6 loop of 3 times with time unit microseconds (usec)
# python2 with type/isinstance diff
python2 -m timeit -n 1000000 'type("A") in (list,basestring)'
1000000 loops, best of 3: 0.143 usec per loop
python2 -m timeit -n 1000000 'isinstance("A", (list,str))'
1000000 loops, best of 3: 0.234 usec per loop
# python3 with type/isinstance diff
python3 -m timeit -r 3 -n 1000000 -u usec 'type("A") in (list,str)'
1000000 loops, best of 3: 0.179 usec per loop
python3 -m timeit -r 3 -n 1000000 -u usec 'isinstance("A", (list,str))'
1000000 loops, best of 3: 0.188 usec per loop
# python2/3 multiple type check. isinstance only support tuple
python3 -m timeit -r 3 -n 1000000 -u usec 'type("A") in [list,str]'
1000000 loops, best of 3: 0.208 usec per loop
python2 -m timeit -n 1000000 'type("A") in [list,str]'
1000000 loops, best of 3: 0.212 usec per loop
# python2/3 multiple type check using + in list
python2 -m timeit -n 1000000 'type("A") in [list,str]+[int]'
1000000 loops, best of 3: 0.52 usec per loop
python3 -m timeit -r 3 -n 1000000 -u usec 'type("A") in [list,str]+[int]'
1000000 loops, best of 3: 0.34 usec per loop
If microseconds level performance is a problem, I think we should also consider using tuple instead of list or even plus to do type check
from objectpath.
from objectpath.
from objectpath.
I tried on my local machine, all tests passed. Could you please list which tests failed?
from objectpath.
from objectpath.
from objectpath.
from objectpath.
I saw it throws TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
on lineif isinstance(obj, tuple(ITER_TYPES + [dict]))
.
It's due to the python 2 handling process on map
and filter
. Actually something like type(map(string.lower, 'ABC')) is map
is alsoFalse
in python2, but covered by the in list
check.
The NameError would only raise when it's python 1 for map and filter.
What's your opinion to fix this problem? Using Python version check maybe a good solution.
from objectpath.
I created a PR #93 to fix this failure.
from objectpath.
Related Issues (20)
- "key in $" no support for existence on root level HOT 2
- License clarification HOT 1
- Complience with Python 3.8 SyntaxWarning when comparing with a literal HOT 1
- objectpath.Tree(jsoncontent).execute('$.*') is raise error 'Syntax error' HOT 1
- date and time from string HOT 7
- Rethink the way ObjectPath **and** operator works
- Average Age of date objects HOT 2
- OpenWeatherMap JSON file is broken HOT 1
- ValueError: generator already executing HOT 1
- return full path
- Support for query by key using data from a list
- TypeError when calling tree.execute() HOT 2
- python3
- json_normalize usage HOT 1
- Nested array query issue HOT 2
- Issue with attribute names consisting of a string with just a number inside? HOT 1
- pytz dependency missing in current pypi latest version (0.6.1) HOT 3
- no list of supported operators HOT 1
- Matching a string that includes single quote. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objectpath.