What is the difference between is_a and instanceof?

后端 未结 9 921
难免孤独
难免孤独 2020-12-04 07:23

I am aware that instanceof is an operator and that is_a is a method.

Is the method slower in performance? What would you prefer to use?

9条回答
  •  囚心锁ツ
    2020-12-04 07:41

    Here is performance results of is_a() and instanceof:

    Test name       Repeats         Result          Performance     
    instanceof      10000           0.028343 sec    +0.00%
    is_a()          10000           0.043927 sec    -54.98%
    

    Test source is here.

提交回复
热议问题