1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Which is faster?

Discussion in 'General discussion' started by AndreKim, Jul 28, 2018.

  1. AndreKim

    AndreKim Silverfish

    Messages:
    22
    GitHub:
    overtook
    1.
    PHP:
    <?php

    namespace UserDB\Task;

    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\AsyncTask;


    class 
    GetTask extends AsyncTask {
     
        private 
    $owner;
        private 
    $player;
     
        public function 
    __construct($ownerPlayer $player){
            
    $this->owner $owner;
            
    $this->player $player;
        }
     
        public function 
    onRun()
        {
            while(
    true){
                
    $this->player->sendMessage("aaa");
                
    usleep(100);
            }
        }
    }
    2.
    PHP:
    <?php

    namespace UserDB\Task;

    use 
    pocketmine\Player;

    class 
    GetTask extends PluginTask {
     
        private 
    $owner;
        private 
    $player;
     
        public function 
    __construct($ownerPlayer $player){
            
    $this->owner $owner;
            
    $this->player $player;
        }
     
        public function 
    onRun(int $currentTick)
        {
            
    $this->player->sendMessage("aaa");
        }
    }

    ===========

    <?
    php

    declare(strict_types=1);

    namespace 
    UserDB\Task;

    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\scheduler\Task;

    abstract class 
    PluginTask extends Task{
     
        
    /** @var Plugin */
        
    protected $owner;
     
        
    /**
         * @param Plugin $owner
         */
        
    public function __construct(Plugin $owner){
            
    $this->owner $owner;
        }
     
        
    /**
         * @return Plugin
         */
        
    final public function getOwner() : Plugin{
            return 
    $this->owner;
        }
     
    }
    The Task of the second method will be executed every 0.1 seconds

    which is faster? I'll use more than 100 tasks.
     
  2. hikingjungle

    hikingjungle Baby Zombie

    Messages:
    123
    GitHub:
    hikingjungle
    faster as in less laggy when you have 100 tasks?
     
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Async tasks are better but... why 100 tasks? You could schedule a repeating one and check if the player's name is in array.
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I don't think you have an idea about the use case of async tasks or just asynchronization in general.

    You need to do a lot more research on the impact of executing 100s of them even if it were possible to do what you are trying to accomplish through async tasks (it isn't possible as of now).

    Async tasks have very little to do with performance, it is performance at a cost. Also, the cost might be higher in PHP than in most of the C-based languages.

    Why are you trying to do it asynchronously (not considering that it is impossible)?
     
  5. AndreKim

    AndreKim Silverfish

    Messages:
    22
    GitHub:
    overtook
    I put in a simple code to hide my code, but actually I do heavy work in there.
    (I know can't use Player class in AsyncTask)
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Muqsit wants to say there are only 2 async workers
     
  7. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    No
     
    Muqsit likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.