Tags down


Racket streams slower than custom streams?

By : Saravanan
Date : October 18 2020, 06:10 AM
Any of those help Here is an observation:
Using a version of integers-starting-from-stream that prints the numbers as they are generated:
code :
(define (integers-starting-from-stream n)
  (stream-cons n
                 (display (~a n " "))
                 (integers-starting-from-stream (+ n 1)))))
(define (integers-starting-from n)
  (s-cons n
          (begin (display (~a n " "))
                 (integers-starting-from (+ n 1)))))
(collect-garbage) (collect-garbage) (collect-garbage)
(time (stream-limit (sieve x) 10))
(collect-garbage) (collect-garbage) (collect-garbage)
(time (s-limit (s-sieve s-x) 10))
(define (integers-starting-from-stream n)
  (stream-cons (begin (sleep 1) n)
               (integers-starting-from-stream (+ n 1))))
(define (integers-starting-from n)
  (s-cons (begin (sleep 1) n)
          (integers-starting-from (+ n 1))))
(collect-garbage) (collect-garbage) (collect-garbage)
(define x (integers-starting-from-stream 2))
(time (stream-limit x 10))
(time (stream-limit x 10))
(collect-garbage) (collect-garbage) (collect-garbage)
(define s-x (integers-starting-from 2))
(time (s-limit s-x 10))
(time (s-limit s-x 10))

Share : facebook icon twitter icon

streams in racket

By : sangeetha
Date : March 29 2020, 07:55 AM
I wish this helpful for you For a general understanding of streams in Scheme, I'd recommend section §3.5 Streams in the SICP book. It'll teach you the basic concepts to solve stream-related problems such as the one in the question.
Regarding the problem in the question, here's the general idea to solve it:

Java 8's streams: why parallel stream is slower?

By : dale
Date : March 29 2020, 07:55 AM
Any of those help There are several issues going on here in parallel, as it were.
The first is that solving a problem in parallel always involves performing more actual work than doing it sequentially. Overhead is involved in splitting the work among several threads and joining or merging the results. Problems like converting short strings to lower-case are small enough that they are in danger of being swamped by the parallel splitting overhead.
code :
package com.stackoverflow.questions;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.*;

public class SO23170832 {
    public static class BenchmarkState {
        static String[] array;
        static {
            array = new String[1000000];
            Arrays.fill(array, "AbabagalamagA");

    public List<String> sequential(BenchmarkState state) {
                  .map(x -> x.toLowerCase())

    public List<String> parallel(BenchmarkState state) {
                  .map(x -> x.toLowerCase())
java -jar dist/microbenchmarks.jar ".*SO23170832.*" -wi 5 -i 5 -f 1
Benchmark                       Mode   Samples         Mean   Mean error    Units
c.s.q.SO23170832.parallel      thrpt         5        4.600        5.995    ops/s
c.s.q.SO23170832.sequential    thrpt         5        1.500        1.727    ops/s
java -verbose:gc -jar dist/microbenchmarks.jar ".*SO23170832.*" -wi 5 -i 5 -f 1
[GC (Allocation Failure)  512K->432K(130560K), 0.0024130 secs]
[GC (Allocation Failure)  944K->520K(131072K), 0.0015740 secs]
[GC (Allocation Failure)  1544K->777K(131072K), 0.0032490 secs]
[GC (Allocation Failure)  1801K->1027K(132096K), 0.0023940 secs]
# Run progress: 0.00% complete, ETA 00:00:20
# VM invoker: /Users/src/jdk/jdk8-b132.jdk/Contents/Home/jre/bin/java
# VM options: -verbose:gc
# Fork: 1 of 1
[GC (Allocation Failure)  512K->424K(130560K), 0.0015460 secs]
[GC (Allocation Failure)  933K->552K(131072K), 0.0014050 secs]
[GC (Allocation Failure)  1576K->850K(131072K), 0.0023050 secs]
[GC (Allocation Failure)  3075K->1561K(132096K), 0.0045140 secs]
[GC (Allocation Failure)  1874K->1059K(132096K), 0.0062330 secs]
# Warmup: 5 iterations, 1 s each
# Measurement: 5 iterations, 1 s each
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.stackoverflow.questions.SO23170832.parallel
# Warmup Iteration   1: [GC (Allocation Failure)  7014K->5445K(132096K), 0.0184680 secs]
[GC (Allocation Failure)  7493K->6346K(135168K), 0.0068380 secs]
[GC (Allocation Failure)  10442K->8663K(135168K), 0.0155600 secs]
[GC (Allocation Failure)  12759K->11051K(139776K), 0.0148190 secs]
[GC (Allocation Failure)  18219K->15067K(140800K), 0.0241780 secs]
[GC (Allocation Failure)  22167K->19214K(145920K), 0.0208510 secs]
[GC (Allocation Failure)  29454K->25065K(147456K), 0.0333080 secs]
[GC (Allocation Failure)  35305K->30729K(153600K), 0.0376610 secs]
[GC (Allocation Failure)  46089K->39406K(154624K), 0.0406060 secs]
[GC (Allocation Failure)  54766K->48299K(164352K), 0.0550140 secs]
[GC (Allocation Failure)  71851K->62725K(165376K), 0.0612780 secs]
[GC (Allocation Failure)  86277K->74864K(184320K), 0.0649210 secs]
[GC (Allocation Failure)  111216K->94203K(185856K), 0.0875710 secs]
[GC (Allocation Failure)  130555K->114932K(199680K), 0.1030540 secs]
[GC (Allocation Failure)  162548K->141952K(203264K), 0.1315720 secs]
[Full GC (Ergonomics)  141952K->59696K(159232K), 0.5150890 secs]
[GC (Allocation Failure)  105613K->85547K(184832K), 0.0738530 secs]
1.183 ops/s

Do Racket streams memoize their elements?

By : user2605215
Date : March 29 2020, 07:55 AM
it helps some times The built-in racket/stream library uses lazy evaluation and memoization to draw elements from a stream:
code :
(require racket/stream)

(define (print-and-return x)
  (displayln "drawing element...")

(define (in-range-stream n m)
  (if (= n m)
      (stream-cons (print-and-return n) (in-range-stream (add1 n) m))))

(define s (in-range-stream 5 10))

(stream-first s)
(stream-first s)
(stream-first (stream-rest s))

How Racket streams work in this case?

By : Belyavskiy Evgeniy
Date : March 29 2020, 07:55 AM
To fix this issue This is a standard trick that makes it possible for lazy streams to be defined in terms of their previous element. Consider a stream as an infinite sequence of values:
code :
s = x0, x1, x2, ...
map(f, s) = f(x0), f(x1), f(x2), ...
s = 1, map(f, s)
  = 1, f(x0), f(x1), f(x2), ...
f(x) = x * 2

s = 1, map(f, s)
  = 1, f(x0), f(x1), f(x2), ...
  = 1, f(1),  f(x1), f(x2), ...
  = 1, 2,     f(x1), f(x2), ...
  = 1, 2,     f(2),  f(x2), ...
  = 1, 2,     4,     f(x2), ...
  = 1, 2,     4,     f(4),  ...
  = 1, 2,     4,     8,     ...

Streams in Java are much slower than native for loop - why?

By : cvalentin
Date : March 29 2020, 07:55 AM
Does that help explaining this entirely would take a lot of time; but what you are testing here is the "cold" start, basically without much JIT and a simple loop is not allocating Objects like a Stream solution - thus a lot less time. Streams have an infrastructure to run on - that takes a while to "heat" up to become more performant.
Those portions of the code are not equivalent either, as in one you are using Math::max, in the one one a plain >. You could test this code iterating a lot more and see the results, but even so you should probably use a tool that is tailored for micro-benchmarks, I know about JMH (and Caliper from google - but I trust only the first one).
Related Posts Related Posts :
  • what does the s3 prefix means with respect to scale?
  • Cassandra slow performance on AWS
  • Why does performance drop when a function is moved to another module?
  • My Cors Preflight Options Request Seems Slow
  • Is there a "Try" equivelent of DATETIME2FROMPARTS?
  • Python-iris performing very slowly in reading netcdf datasets
  • Matrix vs function for matrix operations
  • Find similarities between two lists
  • H2o: Is there a way to fix threshold in H2ORandomForestEstimator performance during training and testing?
  • Does it make sense to use n_jobs = -1 both for inner and outer loop?
  • How is APL optimized to have great performance at array processing? What are some example tricks and optimizations it pe
  • How do I interpret this difference in matrix multiplication GFLOP/s?
  • Why is this simple Haskell program so slow?
  • Why is my pixel manipulation function so slow?
  • How to correctly dockerize and continuously integrate 20GB raw data?
  • Will errorWithoutStackTrace be faster than error when there isn't HasCallStack?
  • Check permission; always a request against database?
  • Performance improvement jsf
  • Does the running of a second thread on an hyperthreaded CPU introduce extra overhead throughout the pipeline?
  • Multiple MPI communications and performance
  • What about type instability hurts peformance so much?
  • Why select distinct partitioned column is very slow?
  • Do FP and integer division compete for the same throughput resources on x86 CPUs?
  • What is FLOPS in field of deep learning?
  • Why does Vec::retain run slower after updating to Rust 1.38.0?
  • Slowdowns of performance of ets select
  • How do I read the Network Tab in Chrome DevTools - Load Times
  • in Snowflake, Does resize an existing warehouse helps in improving the performance of a running query?
  • Do single threaded programs execute in parallel in a CPU?
  • Chrome Web Requests getting stuck for 8 seconds
  • Dynatrace: what is the meaning of srv in dtCookie Cookie set by UEM
  • Why does Raku perform so bad with multidimensional arrays?
  • Neo4j query taking long time
  • What causes this high variability in cycles for a simple tight loop with -O0 but not -O3, on a Cortex-A72?
  • Why is my SSE assembly slower in release builds?
  • From S3 to Snowflake and performance
  • Why these 2 similar queries in Snowflake have very different performance?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk