Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to create a sequence of up to 200-500 thousands numbers in just few microseconds

$
0
0

I need to create a sequence of numbers in the shortest amount of time, ideally in the microseconds range. The total length of this sequence is generally in the range of 20-100 thousand numbers, but sometimes I need to create a sequence of 200-300 thousands numbers. For the moment I have implemented my code in R (just because I know the language fairly well). Assuming my sequence should start from 1 and end up to 25, with an increment of 0.0001, in R I would do

s <- seq(1, 25, by = 0.0001)

Although blazingly fast, this takes few milliseconds to complete

> library(microbenchmark)
> microbenchmark(seq(1, 25, by = 0.0001))
Unit: milliseconds
                   expr    min      lq     mean median     uq     max neval
 seq(1, 25, by = 1e-04) 1.6098 2.14505 3.741858 2.2324 2.3554 83.8912   100

Here my questions:

1- is it possible to make the sequence generation faster in R? ideally < 0.5 milliseconds?

2- at some point I would need to implement the code in another (faster) language, would any language able to generate such a sequences in less then 100-200 microseconds?


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>