title: RxJava - Schedulers vs ExecutorService?
body: <p>I had a hunch that for highly computational, parallelized tasks in RxJava, a traditional <code>ExecutorService</code> would be faster than a <code>Scheduler</code>. </p>
  
  <p>I had a theory that this code</p>
  
  <pre><code>Observable&lt;MyItem&gt; source = ...
  
  source.flatMap(myItem -&gt; myItem.process().subscribeOn(Schedulers.computation()))
  .subscribe();
  </code></pre>
  
  <p>would run slower than this</p>
  
  <pre><code>final ExecutorService svc = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
  Observable&lt;MyItem&gt; source = ...
  
  source.flatMap(myItem -&gt; myItem.process().subscribeOn(Schedulers.from(svc)))
  .finallyDo(svc::shutdown)
  .subscribe();
  </code></pre>
  
  <p>I compared these two approaches with a typical parallel process I do at work, and I got the following results.</p>
  
  <pre><code>EXECUTOR
  
  START: 2016-01-25T09:47:04.350
  END: 2016-01-25T09:48:37.181
  TOTAL TIME (SEC): 92
  
  
  COMPUTATION SCHEDULER
  
  START: 2016-01-25T09:50:37.799
  END: 2016-01-25T09:54:23.674
  TOTAL TIME (SEC): 225
  </code></pre>
  
  <p>So my rough testing has shown the traditional <code>ExecutorService</code> is much faster than a <code>Scheduler</code> for computation.</p>
  
  <p>Is there a reason for these results? Are RxJava schedulers just not optimized for parallelization? I've gotten the impression that computation schedulers use lesser threads than Executors.</p>