您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

实施接口的开销

实施接口的开销

无法抗拒并对其进行了测试,而且看起来几乎没有开销。

参加者有:

Interface IFoo    defining a method
class Foo: IFoo   implements IFoo
class Bar         implements the same method as Foo, but no interface involved

所以我定义

Foo realfoo = new Foo();
IFoo ifoo = new Foo();
Bar bar =  new Bar();

然后调用方法,该方法执行20个字符串连接,每个变量进行10,000,000次。

realfoo:   723 Milliseconds
ifoo:      732 Milliseconds
bar:       728 Milliseconds

如果该方法不执行任何操作,则实际调用会更加突出。

  realfoo: 48 Milliseconds
  ifoo: 62 Milliseconds
  bar: 49 Milliseconds
其他 2022/1/1 18:28:02 有588人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶