How to determine whether the file is 2D or 3D?

What I would like to code is this:

I enter the DXF file, and as soon as I find the first line segment that contains a non-zero Z value, I return: “This is a 3D file”. I am even willing to return a “2D” answer after inspecting the first dozen points or so.

Given the callback architecture of the library (or my newbieness) what I have is a counter of non-zero Z points. This approach can be excruciatingly slow, specially when dealing with a large number of files.

TIA,

-RFH