From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.bugs Subject: bug#71573: Related functions from ts.el Date: Sat, 22 Jun 2024 16:54:42 -0500 Message-ID: References: <0f564d69-2d04-49b9-935d-15ed8741c7ba@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18864"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: Stefan Kangas , 71573@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 22 23:55:31 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sL8hl-0004gD-FJ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Jun 2024 23:55:31 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sL8hM-0007OI-RV; Sat, 22 Jun 2024 17:55:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sL8hK-0007Nr-LR for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:55:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sL8hK-0000yw-Bz for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:55:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sL8hK-0005sf-6j for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Adam Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Jun 2024 21:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71573 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 71573-submit@debbugs.gnu.org id=B71573.171909328722567 (code B ref 71573); Sat, 22 Jun 2024 21:55:02 +0000 Original-Received: (at 71573) by debbugs.gnu.org; 22 Jun 2024 21:54:47 +0000 Original-Received: from localhost ([127.0.0.1]:33424 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL8h5-0005rv-FK for submit@debbugs.gnu.org; Sat, 22 Jun 2024 17:54:47 -0400 Original-Received: from blue.aspen.relay.mailchannels.net ([23.83.221.20]:1853) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL8h2-0005rj-Pu for 71573@debbugs.gnu.org; Sat, 22 Jun 2024 17:54:46 -0400 X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id EFE43829B7; Sat, 22 Jun 2024 21:54:43 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a235.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 8A3DE8343F; Sat, 22 Jun 2024 21:54:43 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1719093283; a=rsa-sha256; cv=none; b=I5Qs79jKvJdeQyJBk+QXwdILVADjLZTIiwtLlamZlfTigwoISDkWuop6OCzecdPYSR60om qjPXFvh1TJE4XZDU/Tr1nG44AGPWb07wgDt7eP7n+HUOOwL7NJWlMWYgKVJkEllK35bZuC 4H1qLZ9DijrmA1R62W3keir7g1hKtMWyJQh0GaBkmCld3TUwLMPW8lCa2sbe0iCt9V6WoG exUceqnrRAxlJw2qWq0A9pd/lzfI2FyUUR1kqKI8DIk0YJZXkyFTeB7px9PGVmKJ/ec+8+ JaUJqFVIzFz7X1LszApz6j3TaxFUMvw8MNw68i6n0mJij/N2aZhIRS+27Dcptg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1719093283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hwJdZyAP8rTCf+g4pvCXrRU2EeoqbcRPvocxImHbX3c=; b=R4zriHqXinTRg1IYYvHJmCTOkEDQJYGPZrFoMHZjHFV9DcCzGEPq6e0y5nOkr2lgqzdv+0 vA9yC2LeBoE1VWByWUXiQ7o170El+xbKTtjRtViW/XUpYC8ZtsdWWn6G6v5fQErvuH0gGs 4c6ROkgZr9fzpmXaglcezNO/AglvuNnjhmPofXrnoC1m4tA7bHhQVYakvoo//5ce9n8BN/ 3wPDsfmjfzPHqQVX/EDXni1laujbpus/hq812as475VuBIX8APsShwJ2+2aXIbUN73W0em P6GsW7csXMEc3OANa2piIP2ZbQpxJq5e5RFxxEtbg4hoRpuv+Z3DN/ztHk1hlw== ARC-Authentication-Results: i=1; rspamd-7f76976655-9hqsp; auth=pass smtp.auth=dreamhost smtp.mailfrom=adam@alphapapa.net X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net X-MC-Relay: Junk X-MailChannels-SenderId: dreamhost|x-authsender|adam@alphapapa.net X-MailChannels-Auth-Id: dreamhost X-Tart-Attack: 1a5e75a53e162b2e_1719093283798_2798637829 X-MC-Loop-Signature: 1719093283797:2643423600 X-MC-Ingress-Time: 1719093283797 Original-Received: from pdx1-sub0-mail-a235.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.102.231.70 (trex/6.9.2); Sat, 22 Jun 2024 21:54:43 +0000 Original-Received: from [10.17.178.125] (unknown [172.98.33.7]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adam@alphapapa.net) by pdx1-sub0-mail-a235.dreamhost.com (Postfix) with ESMTPSA id 4W67LC14GWz2D; Sat, 22 Jun 2024 14:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alphapapa.net; s=dreamhost; t=1719093283; bh=hwJdZyAP8rTCf+g4pvCXrRU2EeoqbcRPvocxImHbX3c=; h=Date:Subject:To:From:Content-Type:Content-Transfer-Encoding; b=jiqtIftku81odNTPdXLF+MXugTvVJ2PG85sGJKXRNDBGg6YJ74cMzlzDanm97HwK9 nc2jXGAmrG1Y02NrlLWk/2p2Av6Sv5BT/k9RlnOfPxaEmA4RGah/dHesDwiQ8vkxho xopTE+Tayh/t6FeCPCWc9lX6xRKbKn87WHM2aPVuIIN2l0BXCoVykVfMqq/VevYeUX HDjOTO97D14Q/4uOVta5Pp6CnwzrYp+IDUv38Eqg8wOuAL7+IymId2fC85M7fbNg76 SfsMxJG4jxO654o4vxc7yB8yq3jUYriKQ2QrzlCJaTNmsDLQjkD90VpRdva0W8D2mj OFiefCoZ1rWzQ== Content-Language: en-US In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287740 Archived-At: On 6/22/24 05:55, Stefan Kangas wrote: > Adam Porter writes: > >> ;; See also the built-in function `format-seconds', which I seem to have >> ;; overlooked before writing this. However, a quick benchmark, run >> ;; 100,000 times, shows that, when controllable formatting is not needed, >> ;; `ts-human-format-duration' is much faster and generates less garbage: >> >> ;; | Form | x faster than next | Total runtime | # >> of GCs | Total GC runtime | >> ;; >> |--------------------------+--------------------+---------------+----------+------------------| >> ;; | ts-human-format-duration | 5.82 | 0.832945 | >> 3 | 0.574929 | >> ;; | format-seconds | slowest | 4.848253 | >> 17 | 3.288799 | > > Is this used a lot in hot loops? IOW, is it worth optimizing? It can be. Imagine formatting timestamps for thousands of items in a vtable. And imagine that happening frequently, e.g. if the vtable is redrawn automatically to account for data having arrived over the network. > If yes, how about adding something like what you have as an optimization > to `format-seconds` for when the format is very simple? Would that > remove the need for `ts-human-format-duration'? I don't know what form such an optimization would take. Perhaps someone could profile it and optimize some hot spots in it, but I'll have to decline that to-do for now, as my list is much too long already. :) BTW, please note that I don't claim that ts-human-format-duration is superior to format-seconds, because the latter is different and has some additional features. Rather, ts-human-format-duration is an alternative that can sometimes be worth using instead. I present it as food for thought when considering to implement related functionality.