First the attributes of the objects are compared. If these are the same, a the raster cells are compared as well. This can be time consuming, and you may prefer to use a sample instead with all.equal
methods
## S4 method for signature 'SpatRaster,SpatRaster'identical(x, y)