| 
278 | 278 |     let(:log_dev) { '/dev/null' }  | 
279 | 279 |     let(:standard_logger) { Logger.new(log_dev) }  | 
280 | 280 |     let(:hedgelog_logger) { Hedgelog.new(log_dev) }  | 
 | 281 | +    let(:message) { 'log message' }  | 
 | 282 | +    let(:hedgelog_params) { [message] }  | 
281 | 283 | 
 
  | 
282 |  | -    context 'when logging a string' do  | 
283 |  | -      let(:message) { 'log message' }  | 
284 |  | - | 
285 |  | -      context 'when in debug mode' do  | 
286 |  | -        it 'is not be more than 12x slower than standard ruby logger' do  | 
287 |  | -          report = Benchmark.ips(quiet: true) do |bm|  | 
288 |  | -            bm.config(time: 5, warmup: 2)  | 
289 |  | -            bm.report('standard_logger') { standard_logger.debug(message) }  | 
290 |  | -            bm.report('hedgelog_logger') { hedgelog_logger.debug(message) }  | 
291 |  | -          end  | 
 | 284 | +    before :each do  | 
 | 285 | +      standard_logger.level = level  | 
 | 286 | +      hedgelog_logger.level = level  | 
 | 287 | +    end  | 
292 | 288 | 
 
  | 
293 |  | -          standard_benchmark, hedgelog_benchmark = *report.entries  | 
 | 289 | +    shared_context 'logging with context' do  | 
 | 290 | +      let(:hash) { {message: 'dummy=1234'} }  | 
 | 291 | +      let(:array) { ['dummy string', {message: 'dummy=1234'}] }  | 
 | 292 | +      let(:context) { hash }  | 
 | 293 | +      let(:hedgelog_params) { [message, context] }  | 
 | 294 | +      before :each do  | 
 | 295 | +        # add other types to the hash  | 
 | 296 | +        context[:hash] = hash.clone  | 
 | 297 | +        context[:array] = array  | 
 | 298 | +        context[:string] = 'dummy'  | 
 | 299 | +        context[:number] = 1234  | 
 | 300 | +      end  | 
 | 301 | +    end  | 
294 | 302 | 
 
  | 
295 |  | -          expect(hedgelog_benchmark.ips).to be > (standard_benchmark.ips / 12)  | 
 | 303 | +    context 'when in debug mode' do  | 
 | 304 | +      let(:level) { Logger::DEBUG }  | 
 | 305 | +      context 'when logging a string' do  | 
 | 306 | +        it 'is no more than 12x slower than the stdlib logger' do  | 
 | 307 | +          expect { standard_logger.debug(message) }.to perform.times_slower(12).than { hedgelog_logger.debug(*hedgelog_params) }  | 
296 | 308 |         end  | 
297 | 309 |       end  | 
 | 310 | +      context 'when logging with context' do  | 
 | 311 | +        include_context 'logging with context'  | 
298 | 312 | 
 
  | 
299 |  | -      context 'when not in debug mode' do  | 
300 |  | -        let(:standard_logger) do  | 
301 |  | -          logger = Logger.new(log_dev)  | 
302 |  | -          logger.level = Logger::INFO  | 
303 |  | -          logger  | 
 | 313 | +        it 'is no more than 16x slower than the stdlib logger' do  | 
 | 314 | +          expect { standard_logger.debug(message) }.to perform.times_slower(16).than { hedgelog_logger.debug(*hedgelog_params) }  | 
304 | 315 |         end  | 
305 |  | -        let(:hedgelog_logger) do  | 
306 |  | -          logger = Hedgelog.new(log_dev)  | 
307 |  | -          logger.level = Logger::INFO  | 
308 |  | -          logger  | 
 | 316 | +      end  | 
 | 317 | +    end  | 
 | 318 | +    context 'when not in debug mode' do  | 
 | 319 | +      let(:level) { Logger::INFO }  | 
 | 320 | +      context 'when logging a string' do  | 
 | 321 | +        it 'is no more than 5x slower than the stdlib logger' do  | 
 | 322 | +          expect { standard_logger.info(message) }.to perform.times_slower(5).than { hedgelog_logger.info(*hedgelog_params) }  | 
309 | 323 |         end  | 
 | 324 | +      end  | 
 | 325 | +      context 'when logging with context' do  | 
 | 326 | +        include_context 'logging with context'  | 
310 | 327 | 
 
  | 
311 |  | -        it 'is not be more than 5x slower than standard ruby logger' do  | 
312 |  | -          report = Benchmark.ips(quiet: true) do |bm|  | 
313 |  | -            bm.config(time: 5, warmup: 2)  | 
314 |  | -            bm.report('standard_logger') { standard_logger.info(message) }  | 
315 |  | -            bm.report('hedgelog_logger') { hedgelog_logger.info(message) }  | 
316 |  | -          end  | 
317 |  | - | 
318 |  | -          standard_benchmark, hedgelog_benchmark = *report.entries  | 
319 |  | - | 
320 |  | -          expect(hedgelog_benchmark.ips).to be > (standard_benchmark.ips / 5)  | 
 | 328 | +        it 'is no more than 12x slower than the stdlib logger' do  | 
 | 329 | +          expect { standard_logger.info(message) }.to perform.times_slower(12).than { hedgelog_logger.info(*hedgelog_params) }  | 
321 | 330 |         end  | 
322 | 331 |       end  | 
323 | 332 |     end  | 
 | 
0 commit comments