JFL kek if you aren't kotlin coroutinmaxing

  • 2 Replies
  • 5325 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 »


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

 


Requirements for functional equivalence to conscious processing?
by DaltonG (General AI Discussion)
November 19, 2024, 11:56:05 am
Will LLMs ever learn what is ... is?
by HS (Future of AI)
November 10, 2024, 06:28:10 pm
Who's the AI?
by frankinstien (Future of AI)
November 04, 2024, 05:45:05 am
Project Acuitas
by WriterOfMinds (General Project Discussion)
October 27, 2024, 09:17:10 pm
Ai improving AI
by infurl (AI Programming)
October 19, 2024, 03:43:29 am
Atronach's Eye
by WriterOfMinds (Home Made Robots)
October 13, 2024, 09:52:42 pm
Running local AI models
by spydaz (AI Programming)
October 07, 2024, 09:00:53 am
Hi IM BAA---AAACK!!
by MagnusWootton (Home Made Robots)
September 16, 2024, 09:49:10 pm
LLaMA2 Meta's chatbot released
by spydaz (AI News )
August 24, 2024, 02:58:36 pm
ollama and llama3
by spydaz (AI News )
August 24, 2024, 02:55:13 pm
AI controlled F-16, for real!
by frankinstien (AI News )
June 15, 2024, 05:40:28 am
Open AI GPT-4o - audio, vision, text combined reasoning
by MikeB (AI News )
May 14, 2024, 05:46:48 am
OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00: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

Users Online

391 Guests, 0 Users

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

Articles