The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hello everybody!

I was trying to implement a sort of Priority Queue, in the code below you can see that when i put a element inside the queue i just sort my array.

I already knew that the performance would not be good but I've noticed that while the test is running my cpu usage reach only 25%.
I was expecting something like 90%.

Some one can explain why this is happening ?

I've run the test directly from the editor and these are the results:

Put_Sort of 100 elements: 28ms
Put_Sort of 200 elements: 120ms
Put_Sort of 300 elements: 298ms
Put_Sort of 400 elements: 565ms
Put_Sort of 500 elements: 924ms
Put_Sort of 600 elements: 1420ms
Put_Sort of 700 elements: 2000ms
Put_Sort of 800 elements: 2690ms
Put_Sort of 900 elements: 3416ms
Put_Sort of 1000 elements: 4365ms

My Test Code

extends Node

class PriorityQueue:

    var queue

    func _init():
        queue = []

    func sort_priority(v1,v2):
        return v1[1] < v2[1]

    func empty():
        return queue.empty()

    func put(vect,priority):
        var pv = [[int(vect.x),int(vect.y)],int(priority)]

    func get():
        var vect = queue[0][0]
        return Vector2(vect[0],vect[1])

func _ready():
    for i in range(10):
        var pq =
        var ms = OS.get_ticks_msec()
        var r=(i+1)*100
        for j in range(r):
            pq.put(Vector2(j,j),randi() % 100)
        print("Put_Sort of ",r," elements: ",OS.get_ticks_msec()-ms,"ms")

Thanks in advance for your help!

in Engine by (22 points)
edited by

About the cpu-usage: Maybe you have a quad-core cpu? Your code is single-threaded, so naturally it can only fully use one core (25% usage on a 4-core machine)

Ty Hinsbart,

you are right, my machine has 4 core, this explains the 25% of cpu usage.

i will try to re-implement my code and try to use more threads.

Thanks again.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.