Permalink
Browse files

Prime time test

  • Loading branch information...
1 parent 1550b47 commit e33dfcae25724dd63762dbc27a4ab6922e9e435a I Heart Robotics committed Mar 18, 2012
@@ -0,0 +1,3 @@
+bin
+build
+lib
@@ -0,0 +1,33 @@
+cmake_minimum_required(VERSION 2.4.6)
+include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
+
+# Set the build type. Options are:
+# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
+# Debug : w/ debug symbols, w/o optimization
+# Release : w/o debug symbols, w/ optimization
+# RelWithDebInfo : w/ debug symbols, w/ optimization
+# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
+#set(ROS_BUILD_TYPE RelWithDebInfo)
+
+rosbuild_init()
+
+#set the default path for built executables to the "bin" directory
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
+#set the default path for built libraries to the "lib" directory
+set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
+
+#uncomment if you have defined messages
+#rosbuild_genmsg()
+#uncomment if you have defined services
+#rosbuild_gensrv()
+
+#common commands for building c++ executables and libraries
+#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
+#target_link_libraries(${PROJECT_NAME} another_library)
+#rosbuild_add_boost_directories()
+#rosbuild_link_boost(${PROJECT_NAME} thread)
+#rosbuild_add_executable(example examples/example.cpp)
+#target_link_libraries(example ${PROJECT_NAME})
+
+rosbuild_add_library(testbench src/primes_testbench_plugin.cpp)
+target_link_libraries(testbench crypto)
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
@@ -0,0 +1,58 @@
+#ifndef PRIMES_TESTBENCH_PRIMES_TESTBENCH_PLUGIN_H_
+#define PRIMES_TESTBENCH_PRIMES_TESTBENCH_PLUGIN_H_
+#include "ros/ros.h"
+#include <testbench/test_base.h>
+#include <cmath>
+#include <time.h>
+#include <openssl/bn.h>
+
+
+namespace test_plugins
+{
+ class Primes : public test_base::Test
+ {
+ public:
+ Primes(){}
+
+ void initialize()
+ {
+ }
+
+ double run()
+ {
+ int i;
+ char number[129];
+ int p;
+ double time;
+ BIGNUM *big = BN_new();
+ BIGNUM *r = BN_new();
+ BN_CTX *ctx = BN_CTX_new();
+ clock_t begin, end;
+ begin = clock();
+ for (i=0; i<0x10000; i++) {
+ sprintf(number,"FF00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000%04X",i);
+ BN_hex2bn(&big, number);
+ p = BN_is_prime(big, BN_prime_checks, 0, ctx, NULL);
+ if (p==1) {
+ ROS_DEBUG("number: %s is_prime: %d\n",number,p);
+ ROS_DEBUG("n: %s\n",BN_bn2dec(big));
+ }
+ }
+ end = clock();
+ time = (double)(end-begin)/(double)CLOCKS_PER_SEC;
+ ROS_DEBUG("total time = %6.6f\n", time);
+ BN_free(big);
+ BN_free(r);
+ BN_CTX_free(ctx);
+ if (time < 1) {
+ return (double)1;
+ } else {
+ return (1.0/(1.0+log(time)/10.0));
+ }
+ }
+
+ private:
+
+ };
+};
+#endif
@@ -0,0 +1,14 @@
+/**
+\mainpage
+\htmlinclude manifest.html
+
+\b random_testbench
+
+<!--
+Provide an overview of your package.
+-->
+
+-->
+
+
+*/
@@ -0,0 +1,17 @@
+<package>
+ <description brief="primes_testbench">
+Test checks if several large numbers are prime.
+ </description>
+ <author>I Heart Engineering</author>
+ <license>BSD</license>
+ <review status="unreviewed" notes=""/>
+ <url>http://ros.org/wiki/primes_testbench</url>
+ <depend package="roscpp"/>
+ <depend package="pluginlib"/>
+ <depend package="testbench"/>
+ <export>
+ <testbench plugin="${prefix}/primes_testbench.xml" />
+ </export>
+</package>
+
+
@@ -0,0 +1,5 @@
+<library path="lib/libtestbench">
+ <class name="testbench/test_primes" type="test_plugins::Primes" base_class_type="test_base::Test">
+ <description>Tests the calculation time of checking if several large numbers are prime.</description>
+ </class>
+</library>
@@ -0,0 +1,4 @@
+#include <pluginlib/class_list_macros.h>
+#include <primes_testbench/primes_testbench_plugin.h>
+
+PLUGINLIB_DECLARE_CLASS(testbench, test_primes, test_plugins::Primes, test_base::Test)

0 comments on commit e33dfca

Please sign in to comment.