After realising that the BMX "mod" expression is rather slow, I re-wrote my isodd() and iseven() functions in C rather than use the internal one.

My previous library functions were:

`Function iseven:Int( x:Int )`

Return ((x Mod 2)=0)

End Function

Function isodd:Int( x:Int )

Return Not((x Mod 2)=0)

End Function

This is my C version:

**evenodd.c**`/* Even and Odd functions `

* Si Dunford, 2020

*/

int iseven( const int n )

{

return n % 2 == 0;

}

int isodd( const int n )

{

return n % 2 != 0;

}

Finally; this is my speed test code. I also included a binary AND version that I've used in other languages for comparison:

**test_evenodd.bmx**`SuperStrict`

'EVEN and ODD testing

Import "evenodd.c"

Extern

Function iseven:Int( number:Int )

Function isodd:Int( number:Int )

EndExtern

Const REPETITION:Int = 1000000

Global start:Int, finish:Int

speedtest( "bmx_even ", bmx_iseven )

speedtest( "bmx_odd ", bmx_isodd )

speedtest( "binaryeven ", binaryeven )

speedtest( "binaryodd ", binaryodd )

speedtest( "iseven ", iseven )

speedtest( "isodd ", isodd )

Function speedtest( descr:String, fn:Int( x:Int ) )

start = MilliSecs()

For Local n:Int = -REPETITION To REPETITION

Local result:Int = fn( n )

Next

finish = MilliSecs()

Print( descr+": "+(finish-start) )

End Function

'# Blitzmax isodd() and iseven()

'# Prefixed with "bmx_" to differentiate from new C version

Function bmx_iseven:Int( x:Int )

Return ((x Mod 2)=0)

End Function

Function bmx_isodd:Int( x:Int )

Return Not((x Mod 2)=0)

End Function

'# Binary AND versions

Function binaryeven:Int( x:Int )

Return (x & $00000001 = 0 )

Return True

End Function

Function binaryodd:Int( x:Int )

Return (x & $00000001 = 1 )

Return True

End Function

The results improved things quite a bit:

`bmx_even : 246`

bmx_odd : 234

binaryeven : 238

binaryodd : 253

iseven : 129

isodd : 128

Regards,

Si...