diff --git a/src/test/java/redis/clients/jedis/tests/benchmark/SafeEncoderBenchmark.java b/src/test/java/redis/clients/jedis/tests/benchmark/SafeEncoderBenchmark.java new file mode 100644 index 0000000..bfe1fe9 --- /dev/null +++ b/src/test/java/redis/clients/jedis/tests/benchmark/SafeEncoderBenchmark.java @@ -0,0 +1,38 @@ +package redis.clients.jedis.tests.benchmark; + +import java.io.IOException; +import java.net.UnknownHostException; +import java.util.Calendar; + +import redis.clients.util.SafeEncoder; + +public class SafeEncoderBenchmark { + private static final int TOTAL_OPERATIONS = 10000000; + + public static void main(String[] args) throws UnknownHostException, + IOException { + long begin = Calendar.getInstance().getTimeInMillis(); + + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + SafeEncoder.encode("foo bar!"); + } + + long elapsed = Calendar.getInstance().getTimeInMillis() - begin; + + System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + + " ops to build byte[]"); + + begin = Calendar.getInstance().getTimeInMillis(); + + byte[] bytes = "foo bar!".getBytes(); + for (int n = 0; n <= TOTAL_OPERATIONS; n++) { + SafeEncoder.encode(bytes); + } + + elapsed = Calendar.getInstance().getTimeInMillis() - begin; + + System.out.println(((1000 * TOTAL_OPERATIONS) / elapsed) + + " ops to build Strings"); + + } +} \ No newline at end of file