Skip to content
Advertisement

Which is faster php date functions or carbon?

Carbon is simple PHP API extension for DateTime. I want to know that we can use datetime functions using by installing carbon via composer.

which is faster php datetime functions or carbon ?

Advertisement

Answer

I did some testing regarding your comment comparing DateTime to Carbon functions:

Calling Carbon::now() vs. new DateTime() 100.000 times:

JavaScript

Results from 5 runs (meaning 5x 100.000 calls):

JavaScript

Confirming what I initially wrote:

Since Carbon inherits DateTime it actually adds a little overhead to those calls (Carbon -> DateTime instead of directly DateTime). The main purpose of Carbon is not to be faster than DateTime, but to enhance it’s functionality with commonly used functions.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement