MAWK does not support length(array)?

As Brendan O'Conner writes in this blog, mawk is near 8 times faster than gawk, so I am going to give mawk a go, but I got errors when trying to print the length of an array in mawk using length() function, is it not supported in mawk? or there's another way to get the length of an array in mawk?

mawk code, which produces this error message: mawk: line 1: illegal reference to array a

mawk ' BEGIN { a[1]="string1"; print length(a) } '

gawk code, which works fine and prints 1.

gawk ' BEGIN { a[1]="string1"; print length(a) } '

length() returning the number of elements in the array (when using an array argument) is a non-standard GNU extension...

Then how do I get the length of an array? do I have to loop through the array and count myself?

I guess so. If you assign the values yourself you should automatically know it yourself if you use a loop counter. If you use the split function to fill the array, the returned function value is the number of ellements. You can assign this number to a variable or print it...

E.g.:

$ mawk ' BEGIN { print split("string1",a)} '
1