Coder Social home page Coder Social logo

Comments (11)

adriank avatar adriank commented on July 17, 2024

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.

truebit avatar truebit commented on July 17, 2024

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.

truebit avatar truebit commented on July 17, 2024

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.

adriank avatar adriank commented on July 17, 2024

from objectpath.

adriank avatar adriank commented on July 17, 2024

from objectpath.

truebit avatar truebit commented on July 17, 2024

I tried on my local machine, all tests passed. Could you please list which tests failed?

from objectpath.

adriank avatar adriank commented on July 17, 2024

from objectpath.

truebit avatar truebit commented on July 17, 2024

from objectpath.

adriank avatar adriank commented on July 17, 2024

from objectpath.

truebit avatar truebit commented on July 17, 2024

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.

truebit avatar truebit commented on July 17, 2024

I created a PR #93 to fix this failure.

from objectpath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.