Thread
#feed
    Ch8n

    Ch8n

    1 year ago
    Big-Brain-Kotlin #7 | Equal Sides Share how you would solve this one... Question: For a given array, find Index N where the sum of integers to the left of N is equal to the sum of integers to the right of N, If there is no index that would make this return -1.
    Example:
    
    for an array {1,2,3,4,3,2,1}
    
    output would be 3 because at the 4th position of the array, 
    
    the sum of left side of the index ({1,2,3}) and the sum of the right side of the index ({3,2,1}) both are equal to 6.
    do check out 👇🏻 my solutionhttps://chetangupta.net/bbk7/
    altavir

    altavir

    1 year ago
    Performance measurement without JMH or at least naive large cycle are meaningless and probably completely wrong in this case. The variant with list involves boxing, but it should not increase time by an order and is completely optimized away on some of modern JVM implementations like GraalVM. Actual computation time for this task is in tens of nanoseconds, not miliseconds. You are measuring JVM warm-up time, not the performance. I think it would be better for people to learn thing first and than try to teach others, don't you think?
    Ch8n

    Ch8n

    1 year ago
    Thanks that good insights, can you point me some resources where I build up on knowledge on this.
    altavir

    altavir

    1 year ago
    I think this article could help: https://www.baeldung.com/java-microbenchmark-harness. https://github.com/Kotlin/kotlinx-benchmark has some facilities to do benchmarks in kotlin way.
    Also one needs to study JVM compilation mode switch, warmup and JIT stabilization in order to make any statements about performance. Since you seem to focus on Android, you should also remember that ART does not always work the same way as a desktop JVM. A lot of things to master if you start measuring and comparing things. Actually, I think for novices, the algorithm complexity is important, other things are just confusing.
    Ch8n

    Ch8n

    1 year ago
    points noted .. thanks 🤓
    seb

    seb

    1 year ago
    Did you notice you have a typo in your cover image? 🙂
    Ch8n

    Ch8n

    1 year ago
    uploaded old banner, fixed it now thanks @seb