From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,86b57370403509bc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!gegeweb.org!aioe.org!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Disabling string evaluation in a logging system Date: Tue, 18 May 2010 18:40:45 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: J4HSNf9Eqj44wTz1J3b8lQ.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Tom's custom newsreader Xref: g2news2.google.com comp.lang.ada:11739 Date: 2010-05-18T18:40:45+00:00 List-Id: > In a language like C or C++, I would use the preprocessor: > #define LOG(text, level) if (level > 0) { log.write (text, level) } So write your own specialized preprocessor that adds the "if" statement to calls on log.write before handing the result to the compiler. > I'd like to avoid the string evaluation if the logging is disabled > (because it consumes CPU resources). As usual with "optimizations", the first question is "will this obfuscation actually save significant time?". If the answer, surprisingly, is "yes", then find the few places where log.write is actually called millions of times and manually insert the "if" test in those places.