PERF: speed up data frame comparison when shape differs
- [ ] closes #53945
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).

Speed up data frame (or series) comparison when shapes are different. A noticeable improvement is observed. The following scripts:
```
>>> import pandas as pd
>>> import time
>>> df = pd.DataFrame({1: range(1000), 2: range(1000)})
>>> other = pd.DataFrame({1: range(1001), 2: range(1001)})
>>> start = time.process_time()
>>> df.equals(other)
False
>>> print(time.process_time() - start)
```
gives `0.00019999999999997797` before changes and ` 0.003806999999999894` after.


The underlying perf issue here is that DataManager.equals uses generators, which slows things down there. I'd prefer fixing that directly.

Did you encounter perf. improvements from this fix, outside of `equals` itself? > gives 0.00019999999999997797 before changes and  0.003806999999999894 after.

is this a typo?  looks like "before" is faster > The underlying perf issue here is that DataManager.equals uses generators, which slows things down there. I'd prefer fixing that directly.
> 
> Did you encounter perf. improvements from this fix, outside of `equals` itself?

I did not investigate further. I was trying to fix a corner case discussed in #53945. That said, as raised by @jbrockmendel in the issue, the check on the shape is already done. > > gives 0.00019999999999997797 before changes and  0.003806999999999894 after.
> 
> is this a typo? looks like "before" is faster

Yes, it is a typo. Thanks for pointing out. That said, it is not rigorous, the evaluation should be done on a large sample of data frames with various dimensions. Following discussion in #53945, we can probably close this PR.  This pull request is stale because it has been open for thirty days with no activity. Please [update](https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#updating-your-pull-request) and respond to this comment if you're still interested in working on this. Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen.