aboutsummaryrefslogtreecommitdiffstats
path: root/benchmark/src/data-tasks.el
blob: 99f3efdde58387b0e79491ee4ac4fc8d04e1c547 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
;;; data-tasks.el --- Primitive Operations on Lisp Data Types -*- lexical-binding: t; -*-

;; Copyright (C) 2018 Free Software Foundation, Inc.

;; Author: Gemini Lasswell <gazally@runbox.com>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'erb-task)

(erb-deftask data-tasks-prime-p ()
  "Verify that a large prime number is prime."
  (:version "1.0")
  (erb-task-time (data-tasks-prime-p 2305843009)))

(defun data-tasks-prime-p (n)
  (or (= n 2)
      (and (> n 2)
           (= 1 (% n 2))
           (catch 'not-prime
             (dotimes (i (1+ (truncate (sqrt n))))
               (when (and (> i 2) (zerop (% n i)))
                 (throw 'not-prime nil)))
             t))))

(provide 'data-tasks)
;;; data-tasks.el ends here