JFL kek if you aren't kotlin coroutinmaxing

  • 2 Replies
  • 4532 Views
*

yotamarker

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1003
  • battle programmer
    • battle programming
JFL kek if you aren't kotlin coroutinmaxing
« on: December 11, 2020, 06:26:22 pm »
https://www.youtube.com/watch?v=jYuK1qzFrJg&feature=emb_title

I am studymaxing it now, and let me tell you ! you can forget about threads.
coroutines are far more light weight so you can summon even a million async coroutines. pause and resume code blocks and
set their context. if you want that speed beef up for your AGI, you need to study this. it is now available for use in android studio 4.1 you
just need to add one dependency line of code in the gradle file tbh ngl.

*

yotamarker

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1003
  • battle programmer
    • battle programming
Re: JFL kek if you aren't kotlin coroutinmaxing
« Reply #1 on: December 15, 2020, 08:12:20 pm »
Code
package com.yotamarker.kotlincoro1.playground.fundamentals

import android.arch.lifecycle.ViewModel
import android.support.annotation.RestrictTo
import kotlinx.coroutines.*
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
//@Volatile var fudge = "fudge" //wherever this var is accessed from it will retrieve or save the latest value
var dClassesLv1 = ArrayList<String>()
var sum = 0;
@ExperimentalTime
fun main()= runBlocking{
    dClassesLv1.add("test1");dClassesLv1.add("test2");dClassesLv1.add("test3");dClassesLv1.add("test4");dClassesLv1.add("test5")
    for (i in 1..1000000) {
        dClassesLv1.add("added$i")
    }
    val duration = measureTime {launch(Dispatchers.Default){
        var finished :Boolean = false;
        repeat(dClassesLv1.size){ index ->
            inOut(dClassesLv1.get(index),"ear","skin","eye")
        }}.join()}
        //job.join()
    if(sum>0){
        println("success")
    println(sum);println("duration $duration")}
    val duration2 = measureTime {for (i in 0..dClassesLv1.size-1) {
        inOut(dClassesLv1.get(i),"ear","skin","eye")
    }}
    println("duration1(coroutine) = $duration duration2 = $duration2 sum= $sum")
    }
fun inOut(dClass:String, ear:String, skin:String, eye:String) {
    //mock function
    //print("$ear $skin $eye ")
    //println(dClass)
    sum = sum +1
}

code lines without printing : duration : sync code lines run time, duration2 coroutines async code lines run time
100m : glitches
10m : duration1(coroutine) = 86.9ms duration2 = 50.5ms sum= 20000010
1m : duration1(coroutine) = 47.4ms duration2 = 12.2ms sum= 2000010
100k : duration1(coroutine) = 42.7ms duration2 = 5.81ms sum= 200010
10k: duration1(coroutine) = 40.5ms duration2 = 895us
1k :duration1(coroutine) = 36.3ms duration2 = 160us sum= 2010
100 : duration1(coroutine) = 37.1ms duration2 = 80.8us sum= 210

*

yotamarker

  • Trusty Member
  • **********
  • Millennium Man
  • *
  • 1003
  • battle programmer
    • battle programming
Re: JFL kek if you aren't kotlin coroutinmaxing
« Reply #2 on: December 16, 2020, 06:38:10 am »
Code
package com.yotamarker.kotlincoro1.playground.fundamentals

import android.arch.lifecycle.ViewModel
import android.support.annotation.RestrictTo
import kotlinx.coroutines.*
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import kotlin.time.ExperimentalTime
import kotlin.time.measureTime
//@Volatile var fudge = "fudge" //wherever this var is accessed from it will retrieve or save the latest value
var dClassesLv1 = ArrayList<String>()
var sum = 0;
@ExperimentalTime
fun main()= runBlocking{
    val duration = measureTime {
        exampleAsyncAwait()
    }
    print("async duration = $duration sum $sum")
    val duration2 = measureTime {
        for (i in 0..1000-1) {
            inOut2(dClassesLv1.get(i),"ear","skin","eye")
        }
    }
    print("  sync duration = $duration2 sum $sum")
}

suspend  fun inOut2(get: String, s: String, s1: String, s2: String) {
    delay(10)
    sum=sum+1
}

suspend fun calculateHardThings(startNum: Int): Int {
    delay(1000)
    return startNum * 10
}
fun exampleAsyncAwait() = runBlocking {
    for (i in 1..10000) {
        dClassesLv1.add("test1")
    }
    val startTime = System.currentTimeMillis()
    for (i in 0..10000-1) {
        if(i==9999){async { inOut(dClassesLv1.get(i),"ear","skin","eye") }.join();break}
        async { inOut(dClassesLv1.get(i),"ear","skin","eye") }
    }
    println("async/await result = $sum")

    val endTime = System.currentTimeMillis()
    println("Time taken: ${endTime - startTime}")
}
suspend fun inOut(dClass:String, ear:String, skin:String, eye:String) {
    //mock function
    //print("$ear $skin $eye ")
    //println(dClass)
    delay(10)
    sum = sum +1
}



async/await result = 10000
Time taken: 146
async duration = 151ms sum 10000  sync duration = 15.5s sum 11000
Process finished with exit code 0

so you only see a speed up with real heavy functions. so I guess for image recognition this could work

 


OpenAI Speech-to-Speech Reasoning Demo
by ivan.moony (AI News )
Today at 01:31:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

268 Guests, 1 User
Users active in past 15 minutes:
ivan.moony
[Trusty Member]

Most Online Today: 346. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles