

{"id":11894,"date":"2019-02-09T17:03:43","date_gmt":"2019-02-09T22:03:43","guid":{"rendered":"https:\/\/rud.is\/b\/?p=11894"},"modified":"2019-02-09T21:29:24","modified_gmt":"2019-02-10T02:29:24","slug":"quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp","status":"publish","type":"post","link":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/","title":{"rendered":"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp"},"content":{"rendered":"<p>Over at $DAYJOB&#8217;s blog I&#8217;ve queued up a post that shows how to use our new <a href=\"https:\/\/cran.r-project.org\/web\/packages\/ropendata\/\"><code>ropendata<\/code>?<\/a> package to work with our <a href=\"https:\/\/opendata.rapid7.com\">Open Data<\/a> portal&#8217;s API. I&#8217;m not super-sure when it&#8217;s going to be posted so keep an RSS reader fixed on <a href=\"https:\/\/blog.rapid7.com\/\">https:\/\/blog.rapid7.com\/<\/a> if you&#8217;re interested in seeing it (I may make a small note of it here so it can wind its way into R Weekly &amp; R-bloggers).<\/p>\n<p>The example data used in the post is the public version of what I talked about in <a href=\"https:\/\/rud.is\/b\/2019\/02\/03\/send-udp-probes-with-payloads-and-receive-process-responses-in-r\/\">a recent post here<\/a>, namely the devices discovered exposing the Ubiquity Discovery Protocol.<\/p>\n<p>I&#8217;m quite blessed at work since we have virtually all of our icky payload data pre-processed and in parquet map columns in Athena so I don&#8217;t really have to do much data wrangling once we&#8217;ve fully baked a new study.<\/p>\n<p>The format of the <em>public data<\/em> for the Ubiquiti discovery protocol scan results is a bit different than the base64 encoded data in the previous post in that the payload response is a hex-encoded character string; e.g.<\/p>\n<pre><code class=\"language-plain\">0100009302000a002722bccf9db126fa9a02000a002722bdcf9dc0a80101010006002722bccf9d0a000400006ae40b000c626a732e6572656e696c646f0c00064147352d48500d00104d6f72726f5f446f757261646f5f30330e000102030022584d2e6172373234302e76352e362e332e32383539312e3135313133302e31373439100002e24514000d41697247726964204d35204850\n<\/code><\/pre>\n<p>So, every two characters is a byte (e.g. <code>\"01\"<\/code> is <code>0x01<\/code>).<\/p>\n<p>R has a nice <code>strtoi()<\/code> function for converting a hex-encoded byte into a raw value but it only works for one byte. We can split a string (like the one above) into a character vector of length 2 hex strings in many ways, one of which is using helper functions from the <code>stringi<\/code> package:<\/p>\n<pre><code class=\"language-r\">library(stringi)\nlibrary(magrittr) # for %&gt;%\n\nx &lt;- \"0100009302000a002722bccf9db126fa9a02000a002722bdcf9dc0a80101010006002722bccf9d0a000400006ae40b000c626a732e6572656e696c646f0c00064147352d48500d00104d6f72726f5f446f757261646f5f30330e000102030022584d2e6172373234302e76352e362e332e32383539312e3135313133302e31373439100002e24514000d41697247726964204d35204850\"\n\nstri_sub(x, seq(1, stri_length(x), by = 2), length = 2)\n##   [1] \"01\" \"00\" \"00\" \"93\" \"02\" \"00\" \"0a\" \"00\" \"27\" \"22\" \"bc\" \"cf\" \"9d\" \"b1\" \"26\" \"fa\" \"9a\"\n##  [18] \"02\" \"00\" \"0a\" \"00\" \"27\" \"22\" \"bd\" \"cf\" \"9d\" \"c0\" \"a8\" \"01\" \"01\" \"01\" \"00\" \"06\" \"00\"\n##  [35] \"27\" \"22\" \"bc\" \"cf\" \"9d\" \"0a\" \"00\" \"04\" \"00\" \"00\" \"6a\" \"e4\" \"0b\" \"00\" \"0c\" \"62\" \"6a\"\n##  [52] \"73\" \"2e\" \"65\" \"72\" \"65\" \"6e\" \"69\" \"6c\" \"64\" \"6f\" \"0c\" \"00\" \"06\" \"41\" \"47\" \"35\" \"2d\"\n##  [69] \"48\" \"50\" \"0d\" \"00\" \"10\" \"4d\" \"6f\" \"72\" \"72\" \"6f\" \"5f\" \"44\" \"6f\" \"75\" \"72\" \"61\" \"64\"\n##  [86] \"6f\" \"5f\" \"30\" \"33\" \"0e\" \"00\" \"01\" \"02\" \"03\" \"00\" \"22\" \"58\" \"4d\" \"2e\" \"61\" \"72\" \"37\"\n## [103] \"32\" \"34\" \"30\" \"2e\" \"76\" \"35\" \"2e\" \"36\" \"2e\" \"33\" \"2e\" \"32\" \"38\" \"35\" \"39\" \"31\" \"2e\"\n## [120] \"31\" \"35\" \"31\" \"31\" \"33\" \"30\" \"2e\" \"31\" \"37\" \"34\" \"39\" \"10\" \"00\" \"02\" \"e2\" \"45\" \"14\"\n## [137] \"00\" \"0d\" \"41\" \"69\" \"72\" \"47\" \"72\" \"69\" \"64\" \"20\" \"4d\" \"35\" \"20\" \"48\" \"50\"\n<\/code><\/pre>\n<p>We still need to run that through <code>strtoi()<\/code> and turn it into a raw vector (at least for this use-case):<\/p>\n<pre><code class=\"language-r\">stri_sub(x, seq(1, stri_length(x), by = 2), length = 2) %&gt;%\n  strtoi(base = 16) %&gt;%\n  as.raw()\n##   [1] 01 00 00 93 02 00 0a 00 27 22 bc cf 9d b1 26 fa 9a 02 00 0a 00 27 22 bd cf 9d c0 a8 01\n##  [30] 01 01 00 06 00 27 22 bc cf 9d 0a 00 04 00 00 6a e4 0b 00 0c 62 6a 73 2e 65 72 65 6e 69\n##  [59] 6c 64 6f 0c 00 06 41 47 35 2d 48 50 0d 00 10 4d 6f 72 72 6f 5f 44 6f 75 72 61 64 6f 5f\n##  [88] 30 33 0e 00 01 02 03 00 22 58 4d 2e 61 72 37 32 34 30 2e 76 35 2e 36 2e 33 2e 32 38 35\n## [117] 39 31 2e 31 35 31 31 33 30 2e 31 37 34 39 10 00 02 e2 45 14 00 0d 41 69 72 47 72 69 64\n## [146] 20 4d 35 20 48 50\n<\/code><\/pre>\n<p>On one of my systems, an individual use of that full processing pipeline with the sample string takes about 170\u03bcs which is not bad. But, what if we have half a million of them (as was the case with the blog post for work)? I mean, <em>sure<\/em>, it&#8217;s only about a minute and a half of processing time (with some variance as each bit of input will be of different lengths), but that&#8217;s a painful interactive 1.5 minutes and we still need to wrap that bit of code in a function with some vectorization so it can be used easily.<\/p>\n<p>This is a good example of where the complexity introduced by using a little C++\/Rcpp may be warranted, especially since the <code>BH<\/code> package&mdash;which brings us a ton of capabilities from the Boost C++ library&mdash;has some handy string utilities, including an <code>boost::algorithm::unhex()<\/code> function.<\/p>\n<p>Here&#8217;s one way to attack the problem in C++\/Rcpp within a plain ol&#8217; R session:<\/p>\n<pre><code class=\"language-r\">library(Rcpp)\n\ncppFunction(depends = \"BH\", '\n  List dehexify_cpp(StringVector input) {\n\n    List out(input.size()); \/\/ make room for our return value\n\n    for (unsigned int i=0; i&lt;input.size(); i++) { \/\/ iterate over the input \n\n      if (StringVector::is_na(input[i]) || (input[i].size() == 0)) {\n        out[i] = StringVector::create(NA_STRING); \/\/ bad input\n      } else if (input[i].size() % 2 == 0) { \/\/ likey to be ok input\n\n        RawVector tmp(input[i].size() \/ 2); \/\/ only need half the space\n        std::string h = boost::algorithm::unhex(Rcpp::as&lt;std::string&gt;(input[i])); \/\/ do the work\n        std::copy(h.begin(), h.end(), tmp.begin()); \/\/ copy it to our raw vector\n\n        out[i] = tmp; \/\/ save it to the List\n\n      } else {\n        out[i] =  StringVector::create(NA_STRING); \/\/ bad input\n      }\n\n    }\n\n    return(out);\n\n  }\n', includes = c('#include &lt;boost\/algorithm\/hex.hpp&gt;')\n)\n<\/code><\/pre>\n<p>Now, we have a <code>dehexify_cpp()<\/code> function in our environment, so we can use it on any valid R data. Let&#8217;s see if we get the same results as the <code>stringi<\/code> R version:<\/p>\n<pre><code class=\"language-r\">dehexify_cpp(x)\n## [[1]]\n##   [1] 01 00 00 93 02 00 0a 00 27 22 bc cf 9d b1 26 fa 9a 02 00 0a 00 27 22 bd cf 9d c0 a8 01\n##  [30] 01 01 00 06 00 27 22 bc cf 9d 0a 00 04 00 00 6a e4 0b 00 0c 62 6a 73 2e 65 72 65 6e 69\n##  [59] 6c 64 6f 0c 00 06 41 47 35 2d 48 50 0d 00 10 4d 6f 72 72 6f 5f 44 6f 75 72 61 64 6f 5f\n##  [88] 30 33 0e 00 01 02 03 00 22 58 4d 2e 61 72 37 32 34 30 2e 76 35 2e 36 2e 33 2e 32 38 35\n## [117] 39 31 2e 31 35 31 31 33 30 2e 31 37 34 39 10 00 02 e2 45 14 00 0d 41 69 72 47 72 69 64\n## [146] 20 4d 35 20 48 50\n<\/code><\/pre>\n<p>Apart from it being a list (since we took care of vectorization at the same time) it is, indeed, the same data.<\/p>\n<p>With that tiny bit of fairly straightforward Rcpp\/C++ code we get a substantially faster execution time of around 4\u03bcs. Yep, that&#8217;s not a typo: <em>four<\/em> microseconds.<\/p>\n<p>We&#8217;ll give it a real world test with the payload data from work:<\/p>\n<pre><code class=\"language-r\"># This assumes you have a \"~\/Data\" directory. Put it somewhere\n# else if you don't have a \"~\/Data\" directory.\n\nif (!file.exists(\"~\/Data\/dehexify-sample-data.txt.gz\")) {\n  download.file(\n    url = \"https:\/\/rud.is\/dl\/dehexify-sample-data.txt.gz\", \n    destfile = \"~\/Data\/dehexify-sample-data.txt.gz\"\n  )\n}\n\nchar_hex_lines &lt;- readr::read_lines(\"~\/Data\/dehexify-sample-data.txt.gz\")\n\nlength(char_hex_lines)\n## [1] 501926\n\nres &lt;- dehexify_cpp(char_hex_lines)\n<\/code><\/pre>\n<p>That took just over a second to run on my main development system. But, did it really work? I chose index <code>998<\/code> at random so let&#8217;s poke at it with the tool from the other blog post:<\/p>\n<pre><code class=\"language-r\">udpprobe::parse_ubnt_discovery_response(res[[998]])\n## [Model: N5N; Firmware: XW.ar934x.v5.5.9.21734.140403.1801; Uptime: 13.1 (hrs)\n<\/code><\/pre>\n<p>Aye, it did, indeed, work.<\/p>\n<h3>FIN<\/h3>\n<p>It&#8217;s still early in 2019 and if you haven&#8217;t settled on any resolutions yet or want to substitute out one that isn&#8217;t working so well (who wants to drive to the gym anyway?) with another, perhaps add &#8220;experiment with Rcpp&#8221; to the list since a tiny dose of it can go a very long way into speeding up some tasks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over at $DAYJOB&#8217;s blog I&#8217;ve queued up a post that shows how to use our new ropendata? package to work with our Open Data portal&#8217;s API. I&#8217;m not super-sure when it&#8217;s going to be posted so keep an RSS reader fixed on https:\/\/blog.rapid7.com\/ if you&#8217;re interested in seeing it (I may make a small note [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[829,91,828],"tags":[],"class_list":["post-11894","post","type-post","status-publish","format-standard","hentry","category-c","category-r","category-rcpp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp - rud.is<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp - rud.is\" \/>\n<meta property=\"og:description\" content=\"Over at $DAYJOB&#8217;s blog I&#8217;ve queued up a post that shows how to use our new ropendata? package to work with our Open Data portal&#8217;s API. I&#8217;m not super-sure when it&#8217;s going to be posted so keep an RSS reader fixed on https:\/\/blog.rapid7.com\/ if you&#8217;re interested in seeing it (I may make a small note [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/\" \/>\n<meta property=\"og:site_name\" content=\"rud.is\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-09T22:03:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-10T02:29:24+00:00\" \/>\n<meta name=\"author\" content=\"hrbrmstr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"hrbrmstr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/\"},\"author\":{\"name\":\"hrbrmstr\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"headline\":\"Quick Hit: Speeding Up a Slow\\\/Mundane Task with a Little Rcpp\",\"datePublished\":\"2019-02-09T22:03:43+00:00\",\"dateModified\":\"2019-02-10T02:29:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/\"},\"wordCount\":643,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"articleSection\":[\"C++\",\"R\",\"Rcpp\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/\",\"name\":\"Quick Hit: Speeding Up a Slow\\\/Mundane Task with a Little Rcpp - rud.is\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\"},\"datePublished\":\"2019-02-09T22:03:43+00:00\",\"dateModified\":\"2019-02-10T02:29:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/2019\\\/02\\\/09\\\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/rud.is\\\/b\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Quick Hit: Speeding Up a Slow\\\/Mundane Task with a Little Rcpp\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#website\",\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/\",\"name\":\"rud.is\",\"description\":\"&quot;In God we trust. All others must bring data&quot;\",\"publisher\":{\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rud.is\\\/b\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/rud.is\\\/b\\\/#\\\/schema\\\/person\\\/d7cb7487ab0527447f7fda5c423ff886\",\"name\":\"hrbrmstr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\",\"width\":460,\"height\":460,\"caption\":\"hrbrmstr\"},\"logo\":{\"@id\":\"https:\\\/\\\/i0.wp.com\\\/rud.is\\\/b\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/ukr-shield.png?fit=460%2C460&ssl=1\"},\"description\":\"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7\",\"sameAs\":[\"http:\\\/\\\/rud.is\"],\"url\":\"https:\\\/\\\/rud.is\\\/b\\\/author\\\/hrbrmstr\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp - rud.is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/","og_locale":"en_US","og_type":"article","og_title":"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp - rud.is","og_description":"Over at $DAYJOB&#8217;s blog I&#8217;ve queued up a post that shows how to use our new ropendata? package to work with our Open Data portal&#8217;s API. I&#8217;m not super-sure when it&#8217;s going to be posted so keep an RSS reader fixed on https:\/\/blog.rapid7.com\/ if you&#8217;re interested in seeing it (I may make a small note [&hellip;]","og_url":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/","og_site_name":"rud.is","article_published_time":"2019-02-09T22:03:43+00:00","article_modified_time":"2019-02-10T02:29:24+00:00","author":"hrbrmstr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"hrbrmstr","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/#article","isPartOf":{"@id":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/"},"author":{"name":"hrbrmstr","@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"headline":"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp","datePublished":"2019-02-09T22:03:43+00:00","dateModified":"2019-02-10T02:29:24+00:00","mainEntityOfPage":{"@id":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/"},"wordCount":643,"commentCount":1,"publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"articleSection":["C++","R","Rcpp"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/","url":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/","name":"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp - rud.is","isPartOf":{"@id":"https:\/\/rud.is\/b\/#website"},"datePublished":"2019-02-09T22:03:43+00:00","dateModified":"2019-02-10T02:29:24+00:00","breadcrumb":{"@id":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/rud.is\/b\/2019\/02\/09\/quick-hit-speeding-up-a-slow-mundane-task-with-a-little-rcpp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/rud.is\/b\/"},{"@type":"ListItem","position":2,"name":"Quick Hit: Speeding Up a Slow\/Mundane Task with a Little Rcpp"}]},{"@type":"WebSite","@id":"https:\/\/rud.is\/b\/#website","url":"https:\/\/rud.is\/b\/","name":"rud.is","description":"&quot;In God we trust. All others must bring data&quot;","publisher":{"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rud.is\/b\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/rud.is\/b\/#\/schema\/person\/d7cb7487ab0527447f7fda5c423ff886","name":"hrbrmstr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","url":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","contentUrl":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1","width":460,"height":460,"caption":"hrbrmstr"},"logo":{"@id":"https:\/\/i0.wp.com\/rud.is\/b\/wp-content\/uploads\/2023\/10\/ukr-shield.png?fit=460%2C460&ssl=1"},"description":"Don't look at me\u2026I do what he does \u2014 just slower. #rstats avuncular \u2022 ?Resistance Fighter \u2022 Cook \u2022 Christian \u2022 [Master] Chef des Donn\u00e9es de S\u00e9curit\u00e9 @ @rapid7","sameAs":["http:\/\/rud.is"],"url":"https:\/\/rud.is\/b\/author\/hrbrmstr\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p23idr-35Q","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2969,"url":"https:\/\/rud.is\/b\/2014\/04\/25\/moving-from-system-calls-to-rcpp-interfaces\/","url_meta":{"origin":11894,"position":0},"title":"Moving From system() calls to Rcpp Interfaces","author":"hrbrmstr","date":"2014-04-25","format":false,"excerpt":"Over on the [Data Driven Security Blog](http:\/\/datadrivensecurity.info\/blog\/posts\/2014\/Apr\/making-better-dns-txt-record-lookups-with-rcpp\/) there's a post on how to use `Rcpp` to interface with an external library (in this case `ldns` for DNS lookups). It builds on [another post](http:\/\/datadrivensecurity.info\/blog\/posts\/2014\/Apr\/firewall-busting-asn-lookups\/) which uses `system()` to make a call to `dig` to lookup DNS `TXT` records. The core code\u2026","rel":"","context":"In &quot;Information Security&quot;","block_context":{"text":"Information Security","link":"https:\/\/rud.is\/b\/category\/information-security\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8140,"url":"https:\/\/rud.is\/b\/2018\/02\/06\/quick-and-clean-dmarc-record-processing-with-inline-rcpp\/","url_meta":{"origin":11894,"position":1},"title":"Quick and Clean DMARC Record Processing with &#8220;Inline&#8221; Rcpp","author":"hrbrmstr","date":"2018-02-06","format":false,"excerpt":"Much of what I need to do for work-work involves using tools that are (for the moment) not in R. Today, I needed to test the validity of (and other processing on) DMARC records and I'm loathe to either reinvent the wheel or reticulate bits from a fragmented programming language\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7579,"url":"https:\/\/rud.is\/b\/2017\/12\/17\/mqtt-development-log-on-dsls-rcpp-modules-and-custom-formula-functions\/","url_meta":{"origin":11894,"position":2},"title":"mqtt Development Log : On DSLs, Rcpp Modules and Custom Formula Functions","author":"hrbrmstr","date":"2017-12-17","format":false,"excerpt":"I know some folks had a bit of fun with the previous post since it exposed the fact that I left out unique MQTT client id generation from the initial 0.1.0 release of the in-development package (client ids need to be unique). There have been some serious improvements since said\u2026","rel":"","context":"In &quot;mqtt&quot;","block_context":{"text":"mqtt","link":"https:\/\/rud.is\/b\/category\/mqtt\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3622,"url":"https:\/\/rud.is\/b\/2015\/08\/21\/doh-i-could-have-had-just-used-v8\/","url_meta":{"origin":11894,"position":3},"title":"Doh! I Could Have Had Just Used V8!","author":"hrbrmstr","date":"2015-08-21","format":false,"excerpt":"An R user recently had the need to split a \"full, human name\" into component parts to retrieve first & last names. The full names could be anything from something simple like _\"David Regan\"_ to more complex & diverse such as _\"John Smith Jr.\"_, _\"Izaque Iuzuru Nagata\"_ or _\"Christian Schmit\u2026","rel":"","context":"In &quot;Javascript&quot;","block_context":{"text":"Javascript","link":"https:\/\/rud.is\/b\/category\/javascript\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4527,"url":"https:\/\/rud.is\/b\/2016\/07\/12\/slaying-cidr-orcs-with-triebeard-a-k-a-fast-trie-based-ipv4-in-cidr-lookups-in-r\/","url_meta":{"origin":11894,"position":4},"title":"Slaying CIDR Orcs with Triebeard (a.k.a. fast trie-based &#8216;IPv4-in-CIDR&#8217; lookups in R)","author":"hrbrmstr","date":"2016-07-12","format":false,"excerpt":"The insanely productive elf-lord, @quominus put together a small package ([`triebeard`](https:\/\/github.com\/ironholds\/triebeard)) that exposes an API for [radix\/prefix tries](https:\/\/en.wikipedia.org\/wiki\/Trie) at both the R and Rcpp levels. I know he had some personal needs for this and we both kinda need these to augment some functions in our `iptools` package. Despite `triebeard`\u2026","rel":"","context":"In &quot;Cybersecurity&quot;","block_context":{"text":"Cybersecurity","link":"https:\/\/rud.is\/b\/category\/cybersecurity\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":11911,"url":"https:\/\/rud.is\/b\/2019\/02\/14\/using-the-ropendata-r-package-to-access-petabytes-of-free-internet-telemetry-data-from-rapid7\/","url_meta":{"origin":11894,"position":5},"title":"Using the ropendata R Package to Access Petabytes of Free Internet Telemetry Data from Rapid7","author":"hrbrmstr","date":"2019-02-14","format":false,"excerpt":"I've got a post up over at $DAYJOB's blog on using the ropendata? package to access the ginormous and ever-increasing amount of internet telemetry (scan) data via the Rapid7 Open Data API. It's super-R-code-heavy but renders surprisingly well in Ghost (the blogging platform we use at work) and covers everything\u2026","rel":"","context":"In &quot;R&quot;","block_context":{"text":"R","link":"https:\/\/rud.is\/b\/category\/r\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/11894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/comments?post=11894"}],"version-history":[{"count":0,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/posts\/11894\/revisions"}],"wp:attachment":[{"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/media?parent=11894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/categories?post=11894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rud.is\/b\/wp-json\/wp\/v2\/tags?post=11894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}