How slow is z80 compared to Arduino Uno when they read an output pin if the Z80 is 2.5Mhz??
I/O cycle and cpu herz and is there anything else to consider?
Retrocomputing Stack Exchange is a question and answer site for vintage-computer hobbyists interested in restoring, preserving, and using the classic computer and gaming systems of yesteryear. It only takes a minute to sign up.
Sign up to join this communityHow slow is z80 compared to Arduino Uno when they read an output pin if the Z80 is 2.5Mhz??
I/O cycle and cpu herz and is there anything else to consider?
How slow is z80 compared to Arduino Uno when they read an output pin if the Z80 is 2.5Mhz??
Quite slow.
An IN
instruction to read a port will take 12 (11 with IN A,<port>
) cycles. An AVR IN
takes a single cycle. So a 16 MHz Arduino Uno is about (12/2,500,000) / (1/16,000,000) = 76.8
times faster.
Of course extracting the pin from the byte read will add some more cycles, but won't change the over all picture.
I/O cycle and cpu herz and is there anything else to consider?
Looking at just the I/O instruction will show just a tiny part of the picture. While it gives a rough estimation, speed of an application is usually not defined by this single instruction, but over all code. So a CPU with a dedicated instruction set may execute way certain tasks better than a different one with just a faster I/O instruction.
For example it it's about testing a port bit for being set will take on a 65C02 a single instruction of 5 cycles, where a Z80 (or AVR) has to have at least 3 instructions, puting it somewhere inbetween both.
Bottom Line: Since all three of them are rather simple and similar constructions, any comparsion based on clocks per instruction per MHz will be sufficient for a rough estimate.
IN r,(C)
instruction (including INF
or IN (HL),(C)
partially undocumented instruction). AVR, in turn, has SBIS/SBIC
instructions that allow testing some IO pins in two instructions.
I/O cycle and cpu herz and is there anything else to consider?
If we are talking Arduino then we should also consider software overheads and overall system throughput. The ATmega328 is much faster clock for clock than a Z80, but some Arduino functions need a lot of instructions. DigitalWrite()
for example is about 20 times slower than writing directly to an I/O port.
Interrupt overhead on the ATmega328 can be huge because up to 32 registers may have to be stacked and unstacked, whereas the Z80 has EX AF,AF' and EXX which exchange all registers in a few microseconds.
The Z80 can directly address 64k RAM and run code from it, whereas the ATmega328 only has 2k RAM and can only execute code from Flash. As soon as you need more than 2k the ATmega328 gets very slow, since you must use SPI, I2C or I/O port manipulation to access external RAM. If you want to load and run user programs then it gets slower still, since sketches have to be uploaded and written to flash via the bootloader.
Bottom line - If you took a 2.5MHz Z80 CP/M machine and replaced the CPU board with an Arduino Uno (with sufficient 'glue' logic to interface it to the S100 bus), then converted the OS and user programs into Arduino sketches, how much faster - or slower - would it be?
DigitalWrite()
is slow, in large part, because it's a generalized solution. There are non-generalized solutions which are much faster. Please keep in mind that "Wiring" isn't intended for performance, it's intended to be using by hobbyists.
Sep 8, 2019 at 0:02
As said earlier, AVR core in this arduino runs at 16MHz, and it has ~2 clocks to read a pin.
Z80 has 11 or 12 clocks to read IO port. Thus, it is ~6 times slower in clocks and 6*(16/2.5) ~ 38 times slower in absolute values.
The Arduino Uno has an ATmega328P, which is clocked at 16 MHz so it is considerably faster regarding MHz speed.
Both are 8 bit CPUs, so that is comparable.
I don't know about the efficiency of a Z80 to read a pin, for an Atmel it's selecting the port and pin number.
My guess is (mostly based on the difference in MHz), that the Arduino Uno is faster.
UPDATE: See comment of Curt J. Sampson below.