views:

69

answers:

2

Does AWK uses a lot of processing power? If so, is there a better scripting language to do it? Or should I do it in C itself (where rest of my code is).

+1  A: 

Depends on what you're telling it to do. Most of the work is passed to the regexp engine, which should be similar, no matter what language you use.

Now if you're using an awk script from inside a C program, and you have the resources to just implement the functionality in C too, you're best off doing that. You'll avoid the process creation/termination + communication overhead (which may or may not be a big part of the performance hit you'll get).

For more information, tell us more about your script!

Blindy
Thanks for the reply, in this case: from a C file --> a shell script which calls --> an awk script - which keeps looking at a log file and as a new entry gets in the log file, it gets filtered by the script. If matches the filters set, gets printed in XML format.
hari
Assuming the log file isn't written to too often, this shouldn't matter one way or the other. And if you choose to include the awk script into your C code, you'll have to include the shell script too. It will obviously be faster, but most likely not by much, so you have to weigh cost (time) vs benefit (speed).
Blindy
Of course, having everything in one program helps minimize dependancy failures and makes distribution easier. Food for thought.
Blindy
What if the log is being written too often? Would AWK take too much of cpu then? and something being written in non-awk would be better then?
hari
I think anything anything under ~10 writes/sec on average is fine as long as your script is straighforward. Writing it in C would of course be faster but ymmv on how MUCH faster it would be.
Blindy
Thanks much Blindy for the help. Is there a way I can measure how much CPU is each part of script is taking up? I mean debugging down the AWK script at function or line level?
hari
A: 

If most of your code is in c, It is probably cleaner to use c to do your string processing rather than shelling out.

You can use PCRE directly in your program.

Byron Whitlock