/* * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com * The software in this package is published under the terms of the CPAL v1.0 * license, a copy of which has been included with this distribution in the * LICENSE.txt file. */ package org.mule.el; import static java.util.concurrent.TimeUnit.NANOSECONDS; import static org.mule.runtime.api.message.Message.of; import static org.mule.runtime.core.DefaultEventContext.create; import static org.mule.runtime.core.api.lifecycle.LifecycleUtils.stopIfNeeded; import org.mule.AbstractBenchmark; import org.mule.runtime.api.exception.MuleException; import org.mule.runtime.core.api.Event; import org.mule.runtime.core.api.MuleContext; import org.mule.runtime.core.api.scheduler.SchedulerService; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.TearDown; @OutputTimeUnit(NANOSECONDS) public class SimpleExpressionBenchmark extends AbstractBenchmark { @Param({"mel:payload", "payload"}) private String expression; private MuleContext muleContext; private Event event; @Setup public void setup() throws MuleException { muleContext = createMuleContextWithServices(); event = Event.builder(create(createFlow(muleContext), CONNECTOR_LOCATION)).message(of(PAYLOAD)).build(); } @TearDown public void teardown() throws MuleException { stopIfNeeded(muleContext.getRegistry().lookupObject(SchedulerService.class)); muleContext.dispose(); } @Benchmark public Object evaluatePayload() { return muleContext.getExpressionManager().evaluate(expression, event).getValue(); } }